【发布时间】:2020-12-13 23:39:28
【问题描述】:
我正在尝试使用此 PayPal API:https://developer.paypal.com/docs/api/orders/v2/#orders_create
这是我的 PHP 代码:
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', $uri, [
'headers' => [
'Accept' => 'application/json',
'Accept-Language' => 'en_US',
'Content-Type' => 'application/x-www-form-urlencoded',
'Authorization' => "Bearer " . $this->token
],
'form_params' => [
"intent" => "CAPTURE",
"purchase_units" => [
"amount" => [
"currency_code" => "USD",
"value" => "100.00"
]
]
]
]
);
收到错误:
客户端错误:
POST https://api.sandbox.paypal.com/v2/checkout/orders导致415 Unsupported Media Type响应: {"name":"UNSUPPORTED_MEDIA_TYPE","message":"请求载荷不是 支持","debug_id":"6bd372e5171ee","details":[(截断...)
【问题讨论】:
-
您是否尝试将数据作为 json 发送,as they do in their docs? 在他们的文档中的“Content-Type”下,它说:“媒体类型。对于带有请求正文的操作是必需的.值为application/
,其中格式为json。"