Get Amazon MWS results to Json or Xml and elaborate them

房东的猫 提交于 2019-12-05 02:39:30

The response format documentation suggests that only XML responses will be returned. However, if I'm understanding your OP correctly, you're seeing plain text responses when sent via curl and XML responses when sent via your browser.

If that is correct, then your browser is likely sending a header - probably Accept - that causes Amazon to change the response format. Try adding the following to your cURL setup:

curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/xml' ]);

Instead of application/xml you might also try application/json, but again based on the documentation I'm not hopeful that will work.

If adding the Accept header doesn't work, inspect the headers of the browser request and replicate all that seem relevant in your cURL setup. In particular, note that Amazon MWS documents that you should send a User-Agent header, but it'd surprise me if that changes the returned format.

Hatef

Looking at Amazon MWS documentation they claim:

in response to a HTTP request, Amazon MWS returns an XML file that contains the results of the request. If a request is successful, the response is returned with the data requested. (source).

I think in your case the reason you are receiving a string is the way you are sending your request via cURL. You could try adding:

curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)');

to your cURL request and see if that fixes the problem. For more detail have a look at this answer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!