Php 尝试执行PayPal支付请求时出现HTTP 400错误。(文件获取内容)
尝试发出一个测试请求,但收到一个错误。 我正在使用贝宝支付API文档中的示例请求Php 尝试执行PayPal支付请求时出现HTTP 400错误。(文件获取内容),php,paypal,paypal-sandbox,payment,file-get-contents,Php,Paypal,Paypal Sandbox,Payment,File Get Contents,尝试发出一个测试请求,但收到一个错误。 我正在使用贝宝支付API文档中的示例请求 $data = array ( 0 => array ( 'op' => 'replace', 'path' => '/transactions/0/amount', 'value' => array ( 'total' => '18.37', 'currency' => 'EUR', 'detail
$data = array (
0 =>
array (
'op' => 'replace',
'path' => '/transactions/0/amount',
'value' =>
array (
'total' => '18.37',
'currency' => 'EUR',
'details' =>
array (
'subtotal' => '13.37',
'shipping' => '5.00',
),
),
),
1 =>
array (
'op' => 'add',
'path' => '/transactions/0/item_list/shipping_address',
'value' =>
array (
'recipient_name' => 'Anna Gruneberg',
'line1' => 'Kathwarinenhof 1',
'city' => 'Flensburg',
'postal_code' => '24939',
'country_code' => 'DE',
),
),
);
$url = 'https://api.sandbox.paypal.com/v1/payments/payment';
$options = array(
'http' => array(
'header' => array(
"Content-type: application/json",
"Authorization: Bearer $access_token"
),
'method' => 'POST',
'content' => http_build_query($data)
)
);
print_r($options);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);
返回:警告:文件\获取\内容():无法打开流:HTTP请求失败!HTTP/1.0 400第48行/storage/ssd5/910/7954910/public_html/paypal.php中的错误请求
bool(假)添加
'protocol_version' => '1.1'
到“http”=>array()
e、 g.换行
'method' => 'POST',
到
这将文件_get_contents()使用的HTTP协议从HTTP/1.0更改为HTTP/1.1,PayPal REST API服务器需要HTTP/1.1。我认为您需要使用
FALSE
(全大写)作为第二个参数,或0
。你试过了吗?欢迎来到SO。你的答案将受益于解释为什么这个改变回答了这个问题。
'protocol_version' => '1.1',
'method' => 'POST',