我尝试PHP Curl请求。我有一个简单的PHP脚本,可以通过PHP发送HTTP POST请求。
条件
*Endpoint
https://api.rms.rakuten.co.jp/es/2.0/order/getOrder/
*Request
-Method
"POST"
*Request Header
-Authorization
ESA Base64 (serviceSecret : licenseKey)
*Content-Type
application json; charset=utf-8
*Request Parameter
-Parameter Name/Type
orderNumberList/List <String>
我的代码(php)
<?php
$serviceSecret = "XXXXXXXXXXXXXXXXXXXXXXXX";
$licenseKey = "XXXXXXXXXXXXXXXXXXXXXX";
$ordernum = "534531-20180618-55345321";
$authkey = base64_encode($serviceSecret . ":" . $licenseKey);
$header = array(
"Content-Type: application/json; charset=utf-8",
"Authorization: ESA {$authkey}"
);
$post = array(
"orderNumberList: {$ordernum}"
);
$url = "https://api.test.com/getOrder/";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$xml = curl_exec($ch);
curl_close($ch);
var_dump($xml);
?>
但回应只是这个。
string(73) "{"Results": {"errorCode": "ES04-03","message": "Unsupported Media Type"}}"
下面是一个示例Curl代码。
curl -X POST \
https://api.test.com/getOrder/ \
-H 'Authorization : ESA xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'\
-H 'Content-Type : application / json; charset = utf-8'\
-d '{
"orderNumberList": "543435-20180116-00111801", "524335-20180116-00113801"
}'
任何见解或想法? 提前谢谢。