我的xampp不会加载任何东西,我在gearhost上尝试过,同样的事情,但在另一个免费的主机上,它工作.. json被加载它应该。
这是代码
$username= urlencode($_GET["username"]);
$endpoint = 'https://api.ebay.com/ws/api.dll';
// create the xml request that will be POSTed
$xml = '<?xml version="1.0" encoding="utf-8"?>';
$xml .= '<GetStoreRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
$xml .= '<RequesterCredentials>';
$xml .= '<eBayAuthToken></eBayAuthToken>';
$xml .= '</RequesterCredentials>';
$xml .= '<UserID>'. $username .'</UserID>';
$xml .='<LevelLimit>1</LevelLimit>';
$xml .= '</GetStoreRequest>';
$headers = array(
'X-EBAY-API-COMPATIBILITY-LEVEL:933',
'X-EBAY-API-DEV-NAME:--',
'X-EBAY-API-APP-NAME:--',
'X-EBAY-API-CERT-NAME:--',
'X-EBAY-API-SITEID:0',
'X-EBAY-API-CALL-NAME:GetStore'
);
$session = curl_init($endpoint);
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($session, CURLOPT_POSTFIELDS, $xml);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$responsexml = curl_exec($session);
curl_close($session);
$json = json_encode(simplexml_load_string($responsexml),true);
$obj = json_decode($json,true);
echo $responsexml;
echo $obj;
答案 0 :(得分:1)
试试这个:
$compatabilityLevel = 859;
$return_api_host = 'https://api.ebay.com/ws/api.dll';
$callName = 'GetStore'; //this is changed based on what call you are making
$headers = array(
'Content-Type: text/xml',
'X-EBAY-API-COMPATIBILITY-LEVEL: '.$compatabilityLevel,
'X-EBAY-API-DEV-NAME: '.$devID,
'X-EBAY-API-APP-NAME: '.$appID,
'X-EBAY-API-CERT-NAME: '.$certID,
'X-EBAY-API-CALL-NAME: '.$callName,
'X-EBAY-API-SITEID: 0',
'SOAPAction: "run"');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $return_api_host);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl,CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xmlpost);
//get response from server
$response =curl_exec($curl);
//format response in array
$responsexml = new SimpleXMLElement($response);
显然$ xmlpost元素将包含你发送的xml。 你可以做一个print_r($ responsexml)来查看结果。