2014-09-26 4 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을 실행할 때

$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; 

왜 응답이 덜오고있다 그러나 그것은 다음과 같이 나에게 전체 응답을 제공합니다 : -

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

편집 : -

내가 가진

$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 반환 아무것도 지금 SimpleXMLElement :: asXML 내 응답 형식을 변경합니다. 내가 그나마

+0

이 게시물을 확인하십시오 : http://stackoverflow.com/questions/12755242/xml-not-returning-correct-result-format –

+0

@hardiksolanki 답장을 보내 주셔서 감사합니다.하지만 그 게시물에 내가 SimpleXMLElement :: asXML 하지만 아무 것도 반환 내 편집을 참조하십시오 –

+0

그래, 나는 이미 거기에 답변을 알고 있지만 내 문제를 해결하지 않는 이유는 내가 여기에 새로운 질문을 질문 –

답변

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

환호 !!!! 그게 내가 대답을 ... 고마워 친구가 그 일을했습니다 :) –

+0

@ RakeshShetty 당신이 가장 환영 친구 ... :) –

+0

아마존 mws API에서 일 했습니까? –