2012-02-24 149 views
2

任何人都可以看到我錯過了什麼嗎?我一直沒有得到任何迴應,XML文件是正確的,所以是標題和網址,但我沒有得到任何迴應。ebay api - 通過php發送xml請求

<?php 
    error_reporting(E_ALL); 

    $URL = $_REQUEST['URL']; 
    $site = $_REQUEST['site']; 
    $file = fopen($URL, 'r'); 
    $xmlRequest = fread($file, filesize($URL)); 
    echo "<textarea>" . $xmlRequest . "</textarea>"; //this is me making sure the file 
                //actually contains the xml doc 

    $endpoint = "https://api.sandbox.ebay.com/ws/api.dll"; 
    $session = curl_init($endpoint);      // create a curl session 

    curl_setopt($session, CURLOPT_POST, true);    // POST request type 
    curl_setopt($session, CURLOPT_POSTFIELDS, $xmlRequest); // set the body of the POST 
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // return values as a string - not to std out 
    $headers = array(
     'X-EBAY-API-CALL-NAME: GetCategories', 
     'X-EBAY-API-SITE-ID: ' . $site, 
     'X-EBAY-API-DEV-NAME: *****', 
     'X-EBAY-API-APP-NAME: *****', 
     'X-EBAY-API-CERT-NAME: *****', 
     'X-EBAY-API-COMPATIBILITY-LEVEL: 761', 
     'X-EBAY-API-REQUEST-ENCODING: XML', // for a POST request, the response by default is in the same format as the request 
     'Content-Type: text/xml;charset=utf-8' 
    ); 
    curl_setopt($session, CURLOPT_HTTPHEADER, $headers); //set headers using the above array of headers 

    $responseXML = curl_exec($session);      // send the request 
    curl_close($session); 

    if ($responseXML = '' OR $responseXML = ' ') { 
     echo "Failed!"; 
    } 
    echo $responseXML; 
    return $responseXML; // returns a string 

?> 
+1

這需要進行基本的調試。 Curl具有['curl_error()'](http://php.net/curl_error)函數,它可以告訴你請求發生了什麼問題。 – 2012-02-24 15:34:27

+0

謝謝,我最終發現它,幾乎完全改變了代碼,但我得到它的工作 – CKKiller 2012-02-24 22:06:24

回答

0

試試這個:

$xml_response = simplexml_load_string($responseXML); 

這裏面xml_response的,你必須找到確認

$xml_response->Ack 

值可以爲:警告,失敗或成功,併爲您提供了錯誤的類型(如果請求中有錯誤)