cURL没有返回数据,但Fiddler是

时间:2014-03-16 13:48:26

标签: php api curl

我正在使用cURL进行API调用,并获得奇怪的结果。通过提琴手做同样的要求非常有效。这是我的代码:

$baseUrl = 'https://api.hellosign.com/v3/signature_request/list';

$curl = curl_init($baseUrl );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 20); //timeout in seconds

$verbose = fopen('php://temp', 'rw+');
curl_setopt($curl, CURLOPT_STDERR, $verbose);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_USERPWD, "1d8aed33c694c95119f207be0cf201b1efcaded86620663d34c3cce7004f7b77");

curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    "Accept: text/html, application/xhtml+xml, */*",
    "Accept-Language: en-US",
    "User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
    "Accept-Encoding: gzip, deflate",
    "DNT: 1",
    "Connection: Keep-Alive"
    )
);

//Execute
$json_response = curl_exec($curl);

//Get debug info
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
rewind($verbose);
$verboseLog = stream_get_contents($verbose);

echo "The CURL Verbose Output:\n";
var_dump($verboseLog);

echo "\n\nRaw Response:\n";
var_dump($json_response);

echo "\n\nJson Response:\n";
$response = json_decode($json_response, true);
var_dump( $response );

这会产生以下输出:

The CURL Verbose Output:

string '* About to connect() to api.hellosign.com port 443 (#85)
*   Trying 54.243.76.206...
* Connected to api.hellosign.com (54.243.76.206) port 443 (#85)
* SSL connection using AES256-SHA
* Server certificate:
*    subject: OU=Domain Control Validated; CN=*.hellosign.com
*    start date: 2013-05-17 18:01:01 GMT
*    expire date: 2014-06-06 18:28:08 GMT
*    subjectAltName: api.hellosign.com matched
*    issuer: C=US; ST=Arizona; L=Scottsdale; O=GoDaddy.com, Inc.; OU=http://certificates.godaddy.com/repository; CN=Go Daddy Secure Certification Authority; serialNumber=07969287
*    SSL certificate verify result: self signed certificate in certificate chain (19), continuing anyway.
* Server auth using Basic with user '1d8aed33c694c95119f207be0cf201b1efcaded86620663d34c3cce7004f7b77'
> GET /v3/signature_request/list HTTP/1.1

Authorization: Basic MWQ4YWVkMzNjNjk0Yzk1MTE5ZjIwN2JlMGNmMjAxYjFlZmNhZGVkODY2MjA2NjNkMzRjM2NjZTcwMDRmN2I3Nzo=
Host: api.hellosign.com
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
Accept-Encoding: gzip, deflate
DNT: 1
Connection: Keep-Alive

< HTTP/1.1 200 OK 
< Access-Control-Allow-Headers: Authorization, Origin, X-Requested-With, Content-Type, Accept
< Access-Control-Allow-Methods: GET, POST, OPTIONS
< Access-Control-Allow-Origin: *
< Content-Type: application/json
< Date: Sun, 16 Mar 2014 13:34:29 GMT
< P3P: CP="NOP3PPOLICY"
< Server: Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/0.9.8k PHP/5.3.10
< X-Powered-By: PHP/5.3.10
< transfer-encoding: chunked
< Connection: keep-alive
< 
* Problem (2) in the Chunked-Encoded data
* Closing connection 85
' (length=1705)

Raw Response:

boolean false

Json Response:

null

注意我没有收到回复,并且在Chunked-Encodeded数据中还有#34;问题(2)&#34;来自cURL的错误。

如果我使用相同的网址,标题等...并通过fiddler运行它,或者如果我点击相同的网址并通过浏览器,它运行良好,我得到了我正在寻找的响应。

我已经尝试过每一个卷曲设置,每次谷歌搜索都可能完成,我完全陷入困境。想法?

更新 我可以通过添加以下内容来解决问题:

curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);

不知道为什么我需要这个,或者为什么它解决了问题,因为curl应该为我解决这个问题 - 有谁能解释一下?

0 个答案:

没有答案