向易趣Post Order API获取curl请求,给出空字符串(PHP)
GET/post order/v2/casemanagement/{caseId}调用易趣post order API,给出一个空字符串。有人能弄清楚我的代码哪里出错了吗?我是否正确传递标题?尤其是授权的语法是否正确向易趣Post Order API获取curl请求,给出空字符串(PHP),php,curl,ebay-api,php-curl,Php,Curl,Ebay Api,Php Curl,GET/post order/v2/casemanagement/{caseId}调用易趣post order API,给出一个空字符串。有人能弄清楚我的代码哪里出错了吗?我是否正确传递标题?尤其是授权的语法是否正确 <?php error_reporting(E_ALL); // Turn on all errors, warnings and notices for easier debugging //Seller Authorization Token $userAuthTo
<?php
error_reporting(E_ALL); // Turn on all errors, warnings and notices for easier debugging
//Seller Authorization Token
$userAuthToken= 'Authorization:TOKEN abc123';
//Endpoint URL to Use
$url = "https://api.ebay.com/post-order/v2/casemanagement/xyz";
//Initializle cURL
$connection = curl_init();
//Set Endpoint URL
curl_setopt($connection,CURLOPT_URL,$url);
//Set HTTP Method
curl_setopt($connection, CURLOPT_HTTPGET, true);
//Create Array of Required Headers
$headers = array();
$headers[] = $userAuthToken;
$headers[] = 'Content-Type:application/json';
$headers[] = 'X-EBAY-C-MARKETPLACE-ID:EBAY-DE';
//var_dump($headers);
//set the headers using the array of headers
curl_setopt($connection,CURLOPT_HTTPHEADER,$headers);
//set it to return the transfer as a string from curl_exec
curl_setopt($connection,CURLOPT_RETURNTRANSFER,1);
//stop CURL from verifying the peer's certificate
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
//Execute the Request
$response = curl_exec($connection);
//close the connection
curl_close($connection);
var_dump($response);
添加
curl_setopt($connection,CURLOPT_头,1)代码>
返回标题并查看问题所在
我也不知道这是否重要,但我的headers数组看起来像:
$headers=数组(
“授权:”.“令牌$TOKEN”,
'内容类型:'.'应用程序/json',
“X-EBAY-C-MARKETPLACE-ID:”“EBAY-US”,
“接受:”。“应用程序/json”,
);代码>
所以你可以看到冒号后面有一个空格。试试这段代码,它对我来说很好
<?php
// Your ID and token
$authToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
// The data to send to the API
$post_data = json_encode(array("legacyOrderId"=>"110181400870-27973775001"));
$url = 'https://api.sandbox.ebay.com/post-order/v2/cancellation/check_eligibility';
//Setup cURL
$header = array(
'Accept: application/json',
'Authorization: TOKEN '.$authToken,
'Content-Type: application/json',
'X-EBAY-C-MARKETPLACE-ID: EBAY-UK'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if(curl_errno($ch)){
echo "ERROR:".curl_error($ch);
}
curl_close($ch);
echo json_decode($response,true);
?>
你找到解决问题的方法了吗?我也有同样的方法??注意关闭CURLOPT_SSL_VERIFYPEER并修复您的PHP配置。任何运行最新Linux发行版的人都可能已经可以了,因为他们通过包管理器获得了curl库,最近的curl库附带了来自Mozilla.org的最新CA根证书包。这意味着您只需打开CURLOPT_SSL_VERIFYPEER,就不会出现任何错误。
Array
(
[legacyOrderId] => 110181400870-27973775001
[eligible] => 1
[failureReason] => Array
(
)
[itemEligibilityResult] => Array
(
[0] => Array
(
[itemId] => 110181400870
[transactionId] => 34573775001
[eligible] => 1
[failureReason] => Array
(
)
)
)
[eligibleCancelReason] => Array
(
[0] => OUT_OF_STOCK_OR_CANNOT_FULFILL
[1] => BUYER_CANCEL_OR_ADDRESS_ISSUE
)
)