2016-06-29 152 views
1

我向ebay發送xml請求,但它沒有響應任何內容。我檢查了像runame,header和curl這樣的每個字段,但仍然沒有出現任何錯誤。任何人都可以解決這個問題?Ebay使用curl發送xml請求

$runame = "Th_c_L__B_-ThcLB-SynEbay-S-swfednxx"; 
$xml = '<?xml version="1.0" encoding="utf-8"?>'. 
     '<GetSessionIDRequest xmlns="urn:ebay:apis:eBLBaseComponents">'. 
       '<RuName>'.$runame.'</RuName>'. 
     '</GetSessionIDRequest>'; 

$headers = array(
      'Content-Type' => 'text/xml', 
      'X-EBAY-API-COMPATIBILITY-LEVEL' => '889', 
      'X-EBAY-API-DEV-NAME' => $devId, 
      'X-EBAY-API-APP-NAME' => $appId, 
      'X-EBAY-API-CERT-NAME' => $certId, 
      'X-EBAY-API-SITEID' => '0', 
      'X-EBAY-API-CALL-NAME' => 'GetSessionID' 
    ); 

    $url = 'https://api.sandbox.ebay.com/ws/api.dll'; 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);   
    curl_setopt($ch, CURLOPT_TIMEOUT, 400); 

    $result = curl_exec($ch); 

    curl_close($ch); 


    echo '<pre>'; 
    print_r($result); 
    echo '</pre>'; 
+1

當您使用命令行curl發送相同的XML時會發生什麼? – Nikem

+0

必須有一些方法來獲得有關捲曲結果的更多信息? (HTTP代碼,頭文件等)我建議您挖掘並評估您在那裏找到的內容。 –

回答

0

我發現自己說,這是需要CURLOPT_SSL_VERIFYPEER設置爲false,因爲易趣報答HTTPS和我在本地主機上運行它,它沒有SSL認證。另外,$ headers數組不能使用關聯。

$runame = "Th_c_L__B_-ThcLB-SynEbay-S-swfednxx"; 
$xml = '<?xml version="1.0" encoding="utf-8"?>'. 
     '<GetSessionIDRequest xmlns="urn:ebay:apis:eBLBaseComponents">'. 
      '<RuName>'.$runame.'</RuName>'. 
     '</GetSessionIDRequest>'; 

$headers = array(
      'Content-Type: text/xml', 
      'X-EBAY-API-COMPATIBILITY-LEVEL: 911', 
      'X-EBAY-API-DEV-NAME: ' . $this->devId, 
      'X-EBAY-API-APP-NAME: ' . $this->appId, 
      'X-EBAY-API-CERT-NAME: '. $this->certId, 
      'X-EBAY-API-SITEID: 0', 
      'X-EBAY-API-CALL-NAME: GetSessionID' 
); 

$url = 'https://api.sandbox.ebay.com/ws/api.dll'; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);   
curl_setopt($ch, CURLOPT_TIMEOUT, 400); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 

$result = curl_exec($ch); 

curl_close($ch); 


echo '<pre>'; 
print_r($result); 
echo '</pre>';