簡體   English   中英

ebay api-通過php發送xml請求

[英]ebay api - send xml request via php

誰能看到我所缺少的嗎? 我一直沒有得到任何響應,該xml文件是正確的,標題和url也是如此,但是我沒有得到任何響應。

<?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

?>

嘗試這個:

$xml_response =  simplexml_load_string($responseXML);

在此xml_response內,您必須找到Ack

$xml_response->Ack

值可以是:警告,失敗或成功,並提供錯誤類型(如果請求中有錯誤)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM