Curl以空字符串响应。如何获取更多信息?

时间:2016-07-06 09:03:33

标签: php curl paypal

我得到一个非常奇怪的行为,我不知道如何获得有关正在发生的事情的更多信息...

我正在使用Paypal Express Checkout与NVP API。基本上,我发送请求,Paypal以key1=value1&key2=value2...

回复

我发送第一个curl请求,一切都很顺利。

然后我用curl发送下一个请求,但$result为空。但奇怪的是,如果我打印$paypal_url并将其复制/粘贴到浏览器中,我会得到正确的答案。

所以似乎curl没有发送请求,但我不明白为什么。我怎样才能窥探curl和Paypal之间的交流?或者我怎样才能获得有关正在发生的事情的更多信息?

谢谢!

//First request (fine) : Get Paypal Checkout Details
$paypal_url = $url."?VERSION=204.0&USER=".$user."&PWD=".$pwd."&SIGNATURE=".$signature."&METHOD=GetExpressCheckoutDetails&TOKEN=".$token;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $paypal_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($curl);
curl_close($curl);

//parse the result
parse_str($result);

//Check data integrity (nothing relevant)
if($ACK!="Success" || $token!=$TOKEN || $amount!=$PAYMENTREQUEST_0_AMT || $currency!=$PAYMENTREQUEST_0_CURRENCYCODE) {
    header("HTTP/1.0 402 Payment Required");
    die("Couldn't realize the payment checkout : ".$ACK."  ".$TOKEN."   required: ".$PAYMENTREQUEST_0_AMT."   ".$PAYMENTREQUEST_0_CURRENCYCODE."<br/>".$token."  payed : ".$amount."   ".$currency);
}

//Second request : Do Paypal checkout
$paypal_url = $url;
$paypal_url .= "?VERSION=204.0";
$paypal_url .= "&USER=".$user;
$paypal_url .= "&PWD=".$pwd;
$paypal_url .= "&SIGNATURE=".$signature;
$paypal_url .= "&METHOD=DoExpressCheckoutPayment";
$paypal_url .= "&TOKEN=".$token;
$paypal_url .= "&PAYERID=".$payerid;
$paypal_url .= "&PAYMENTREQUEST_0_PAYMENTACTION=Sale";
$paypal_url .= "&PAYMENTREQUEST_0_AMT=".$amount;
$paypal_url .= "&PAYMENTREQUEST_0_CURRENCYCODE=".$currency;
$paypal_url .= "&PAYMENTREQUEST_0_ITEMAMT =".$amount;

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $paypal_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($curl);
curl_close($curl);

//Display the URL and the result... But the result is missing !
die($paypal_url."\n".$result);

//If I now copy/paste the content of $paypal_url into a browser, I get the expected result.

1 个答案:

答案 0 :(得分:1)

在CURL中启用详细模式...

curl_setopt($curl, CURLOPT_VERBOSE, true);

...并查看正在传输/接收的数据