【发布时间】:2014-02-14 04:59:00
【问题描述】:
在making your first call 上的 PayPal 教程中,它为您提供了一个我发现无法发布的 JSON 字符串。我已经用尽了谷歌,我似乎无法弄清楚如何将这些数据发布到 PayPal。下面的代码给了我一个 415 错误代码(“不支持的媒体类型”)。我已经被这个错误困住了几个小时,并且越来越厌倦它。我会感谢任何可以帮助我的人。我已经尽力让我的描述清楚,以防我们将来找到其他人能够轻松找到的答案。
$post_data = array (
'intent' => 'sale',
'redirect_urls' => array (
'return_url' => 'http://example.com/return',
'cancel_url' => 'http://example.com/cancel'
),
'payer' => array (
'payment_mehod' => 'paypal'
),
'transactions' => array (
'amount' => array (
'total' => '7.47',
'currency' => 'USD'
)
)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment");
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ' . $result_array['access_token']]);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data));
$result = curl_exec($ch);
编辑:在提供的代码的倒数第二行中,我还使用了 http_build_query,并且我也尝试过将其作为多维数组简单地发送。这两个都返回错误代码 415。
【问题讨论】:
标签: php json curl paypal http-status-code-415