我正在尝试使用Curl与服务器的API进行通信:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'pilot-payflowpro.paypal.com');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_HEADER, 1); // tells curl to include headers in response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 45); // times out after 45 secs
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // this line makes it work under https
curl_setopt($ch, CURLOPT_POSTFIELDS, $plist); //adding POST data
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); //verifies ssl certificate
curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE); //forces closure of connection when done
curl_setopt($ch, CURLOPT_POST, 1); //data sent as POST
$result = curl_exec($ch);
$headers = curl_getinfo($ch);
print_r($headers);
但是,$ result变量为空,当returntransfer设置为1时,表示没有给出响应。打印出标题会给出:
( [url] => HTTP://pilot-payflowpro.paypal.com [content_type] => [http_code] => 0
[header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0
[redirect_count] => 0 [total_time] => 1.656 [namelookup_time] => 0.062 [connect_time] => 0
[pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0
[speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1
[starttransfer_time] => 0 [redirect_time] => 0 [certinfo] => Array ( ) )
这在调试方面有何建议?我在本地桌面上使用wamp并启用了curl。
感谢。
答案 0 :(得分:1)
像你一样CURLOPT_URL param是错误的...尝试使用完全填充的网址(http://pilot-payflowpro.paypal.com)
在您的示例中,curl不知道使用哪种协议(http,https)
编辑:尝试使用https://pilot-payflowpro.paypal.com
,因为您提到的服务器没有响应http协议