我正在尝试使用GetSingleItemRequest将XML HTTP POST请求发送到eBay购物api。我已经按照您可以在下面看到的文档设置了请求。问题是我遇到了要解决的错误。我看不出问题是什么!预先感谢您的帮助。
错误:“失败,输入数据无效。给定标签的输入数据无效或丢失。请检查API文档。1.22错误XML文档结构必须在同一实体内开始和结束。RequestErrorE1141_CORE_APILW_19170841_R1 1141”
我的代码(出于安全考虑,我已删除了我的eBay APP ID)
error_reporting(E_ALL);
$endpoint = 'https://open.api.ebay.com/shopping';
// Create headers to send with CURL request.
$headers = array
(
'X-EBAY-API-APP-ID:XXXXXXXXXXXXXXXXXX',
'X-EBAY-API-SITE-ID:3',
'X-EBAY-API-CALL-NAME:GetSingleItem',
'X-EBAY-API-VERSION:1141',
'X-EBAY-API-REQUEST-ENCODING:xml',
);
// Generate XML request
$xml_request = '<?xml version="1.0" encoding="utf-8"?>';
$xml_request .= '<GetSingleItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
$xml_request .= '<IncludeSelector>Details</IncludeSelector>';
$xml_request .= '<ItemID>113989656655</ItemID>';
$xml_request .= '</GetSingleItemRequest>';
$session = curl_init($endpoint); // create a curl session
curl_setopt($session, CURLOPT_HTTPHEADER, $headers); //Add headers
curl_setopt($session, CURLOPT_POST, true); //Set to POST request type
curl_setopt($session, CURLOPT_POSTFIELDS, $xml_request); //Attach XML to request
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); //Return result as string
$result = curl_exec($session); //Execute POST request
if(curl_errno($session)){
throw new Exception(curl_error($session));
}
curl_close($session); //Close the cURL handle.
echo $result; //Print out the response output.