2014-09-26 124 views
0

我正在使用亞馬遜MWS並嘗試使用GetMatchingProductForId從SKU獲取產品詳細信息。這是我得到的迴應是:來自cUrl請求的格式響應

SimpleXMLElement Object 
(
    [GetMatchingProductForIdResult] => SimpleXMLElement Object 
     (
      [@attributes] => Array 
       (
        [Id] => VYPL039_$P 
        [IdType] => SellerSKU 
        [status] => Success 
       ) 

      [Products] => SimpleXMLElement Object 
       (
        [Product] => SimpleXMLElement Object 
         (
          [Identifiers] => SimpleXMLElement Object 
           (
            [MarketplaceASIN] => SimpleXMLElement Object 
             (
              [MarketplaceId] => A21TJRUUN4KGV 
              [ASIN] => B00NA3ZMKM 
             ) 

           ) 

          [AttributeSets] => SimpleXMLElement Object 
           (
           ) 

          [Relationships] => SimpleXMLElement Object 
           (
           ) 

          [SalesRankings] => SimpleXMLElement Object 
           (
           ) 

         ) 

       ) 

     ) 

    [ResponseMetadata] => SimpleXMLElement Object 
     (
      [RequestId] => 9e893248-adaf-43a1-bcae-70f62b6888c7 
     ) 

) 

捲曲請求:

$url = "https://mws.amazonservices.in/Products/2011-10-01" . '?' . $url_string . "&Signature=" . $signature; 
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL,$url); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_TIMEOUT, 15); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
     $response = curl_exec($ch); 

     //echo $url;exit; 

$responseDoc = new DOMDocument(); 
     $responseDoc->loadXML($response); 

     $response = simplexml_import_dom($responseDoc); 

echo '<pre>'; 
     print_r($response); 
     echo '</pre>'; 
     exit; 

但爲什麼響應快到少但是當我在瀏覽器中運行的URL它給了我充分的反應像以下內容: -

<GetMatchingProductForIdResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01"> 
<GetMatchingProductForIdResult Id="VYPL039_$P" IdType="SellerSKU" status="Success"> 
<Products xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd"> 
<Product> 
<Identifiers> 
<MarketplaceASIN> 
<MarketplaceId>A21TJRUUN4KGV</MarketplaceId> 
<ASIN>B00NA3ZMKM</ASIN> 
</MarketplaceASIN> 
</Identifiers> 
<AttributeSets> 
<ns2:ItemAttributes xml:lang="en-IN"> 
<ns2:Binding>Apparel</ns2:Binding> 
<ns2:Brand>Vivekananda Youth Connect</ns2:Brand> 
<ns2:Department>womens</ns2:Department> 
<ns2:Feature>Category :Clothing</ns2:Feature> 
<ns2:Feature>Sleeves : Half</ns2:Feature> 
<ns2:Feature>Trends : Printed</ns2:Feature> 
<ns2:Label>Vivekananda Youth Connect</ns2:Label> 
<ns2:Manufacturer>Vivekananda Youth Connect</ns2:Manufacturer> 
<ns2:MaterialType>Cotton</ns2:MaterialType> 
<ns2:PackageDimensions> 
<ns2:Height Units="inches">2.00</ns2:Height> 
<ns2:Length Units="inches">15.00</ns2:Length> 
<ns2:Width Units="inches">12.00</ns2:Width> 
<ns2:Weight Units="pounds">0.77</ns2:Weight> 
</ns2:PackageDimensions> 
<ns2:PartNumber>VYPL039_$P</ns2:PartNumber> 
<ns2:ProductGroup>Apparel</ns2:ProductGroup> 
<ns2:ProductTypeName>SHIRT</ns2:ProductTypeName> 
<ns2:Publisher>Vivekananda Youth Connect</ns2:Publisher> 
<ns2:SmallImage> 
<ns2:URL> 
http://g-ecx.images-amazon.com/images/G/31/x-site/icons/no-img-sm._V138359930_.gif 
</ns2:URL> 
<ns2:Height Units="pixels">40</ns2:Height> 
<ns2:Width Units="pixels">60</ns2:Width> 
</ns2:SmallImage> 
<ns2:Studio>Vivekananda Youth Connect</ns2:Studio> 
<ns2:Title> 
Vivekananda Youth Connect Happiness Mantra Womens Tshirt_VYPL039_$P 
</ns2:Title> 
</ns2:ItemAttributes> 
</AttributeSets> 
<Relationships> 
<ns2:VariationChild> 
<Identifiers> 
<MarketplaceASIN> 
<MarketplaceId>A21TJRUUN4KGV</MarketplaceId> 
<ASIN>B00NA4AFN0</ASIN> 
</MarketplaceASIN> 
</Identifiers> 
<ns2:Color>Orange</ns2:Color> 
<ns2:Size>36</ns2:Size> 
</ns2:VariationChild> 
<ns2:VariationChild> 
<Identifiers> 
<MarketplaceASIN> 
<MarketplaceId>A21TJRUUN4KGV</MarketplaceId> 
<ASIN>B00NA4AKPI</ASIN> 
</MarketplaceASIN> 
</Identifiers> 
<ns2:Color>Orange</ns2:Color> 
<ns2:Size>38</ns2:Size> 
</ns2:VariationChild> 
<ns2:VariationChild> 
<Identifiers> 
<MarketplaceASIN> 
<MarketplaceId>A21TJRUUN4KGV</MarketplaceId> 
<ASIN>B00NA4AOWC</ASIN> 
</MarketplaceASIN> 
</Identifiers> 
<ns2:Color>Orange</ns2:Color> 
<ns2:Size>40</ns2:Size> 
</ns2:VariationChild> 
</Relationships> 
<SalesRankings/> 
</Product> 
</Products> 
</GetMatchingProductForIdResult> 
<ResponseMetadata> 
<RequestId>161416fd-f047-4b13-93d5-27df3f428c5a</RequestId> 
</ResponseMetadata> 
</GetMatchingProductForIdResponse> 

編輯: -

我有現在改變我的響應格式的SimpleXMLElement :: asXML:

$url = "https://mws.amazonservices.in/Products/2011-10-01" . '?' . $url_string . "&Signature=" . $signature; 
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL,$url); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_TIMEOUT, 15); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
     $response = curl_exec($ch); 

$parsed_xml = simplexml_load_string($response); 
$response = $parsed_xml->asXML(); 

$response任何回報。

+0

請檢查此文章:http://stackoverflow.com/questions/12755242/xml-not-returning-correct-result-format – 2014-09-26 06:04:03

+0

@hardiksolanki感謝您的回覆,但作爲該帖子建議我已經使用SimpleXMLElement :: asXML但它沒有任何回報看到我的編輯 – 2014-09-26 06:18:27

+0

是的我知道答案已經存在,但它不能解決我的問題,這就是爲什麼我在這裏問一個新的問題 – 2014-09-26 06:23:14

回答

2

我不知道這是你或沒有,但它的做工精細妥善的解決辦法對我來說:

$response = str_replace("ns2:","",$response); 
$responseDoc = new DOMDocument(); 
$responseDoc->loadXML($response); 

$response = simplexml_import_dom($responseDoc); 

echo '<pre>'; 
print_r($response); 
echo '</pre>'; 
exit; 

請檢查上面的代碼。

+0

乾杯!多數民衆贊成我叫一個答案...感謝哥們其工作:) – 2014-09-26 07:29:35

+0

@RakeshShetty你最歡迎的兄弟... :) – 2014-09-26 07:30:39

+0

你的工作亞馬遜mws API? – 2014-09-26 07:33:11

相關問題