Формат ответа от запроса cUrl

Я работаю над Amazon MWS и пытаюсь получить информацию о продукте из SKU, используя GetMatchingProductForId. Ответ, который я получаю:

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
)

)

cURL Запрос:

$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

Решение

Я не знаю, правильное ли это решение для вас или нет, но оно работает нормально для меня:

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

$response = simplexml_import_dom($responseDoc);

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

Пожалуйста, проверьте код выше.

2

Другие решения

Других решений пока нет …