来自cUrl请求的格式响应

问题描述:

我正在使用亚马逊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

我不知道这是你或没有,但它的做工精细妥善的解决办法对我来说:

$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