将亚马逊MWS结果获取到Json或Xml并进行详细说明 [英] Get Amazon MWS results to Json or Xml and elaborate them

查看:1921
本文介绍了将亚马逊MWS结果获取到Json或Xml并进行详细说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法以Json或Xml格式而不是纯字符串来获取亚马逊MWS请求的结果?

Is there any way to get results of an Amazon MWS request in the Json or Xml format instead of a plain string?

我的代码如下:

public function listOrders()
{
    $request = "https://mws.amazonservices.it/Orders/2013-09-01?";
    $request .= $this->getParameterString($this->parameters) . "&Signature=" . $this->calculateSignature($this->calculateStringToSign($this->parameters));

    $ch = curl_init();

    // set URL and other appropriate options
    curl_setopt($ch, CURLOPT_URL, $request);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // grab URL and pass it to the browser

    $a = curl_exec($ch);
    echo $a;
    return $a;
}

当显示$ a时我看到这个

when $a is shown I see this (a plain string with few possibilities of elaboration):

2016-11-21T22:59:59Z StandardOrder 2016-11-17T06:24:44Z 2016-11-17T18:47:54Z 1@marketplace.amazon.it 402-2385999-1452355 1 IT Std Domestic Shipped Amazon.it false 0 2016-11-25T22:59:59Z nico 2016-11-20T23:00:00Z EUR 199.00 false 2016-11-17T23:00:00Z APJ6JRA9NG5V4 MFN Other arezzo 3332260766 pratovecchio stia IT 52015 nico via ro 92/94/96 false Standard 2016-11-22T22:59:59Z StandardOrder 2016-11-19T18:35:43Z 2016-11-21T18:14:04Z 2@marketplace.amazon.it 171-6439117-6622751 1 IT Std Domestic Shipped Amazon.it false 0 2016-11-26T22:59:59Z s 2016-11-22T23:00:00Z EUR 130.00 false 2016-11-20T23:00:00Z APJ6JRA9NG5V4 MFN Other CA 3926624273 Cagliari IT 09126 Samuele civico 244 false Standard 2016-11-28T22:59:59Z StandardOrder 2016-11-24T11:30:20Z 2016-11-24T18:46:12Z 3@marketplace.amazon.it 404-3098817-1844319 1 IT Std Domestic Shipped Amazon.it false 0 2016-12-02T22:59:59Z ini 2016-11-27T23:00:00Z EUR 110.00 false 2016-11-24T23:00:00Z APJ6JRA9NG5V4 MFN Other latina 3286028770 terracina IT 04019 ...

但如果我复制$请求我的浏览器,我看到的是一个XML格式的响应。

but if I copy the $request in my browser, what I see is a XML format response.

我该怎么办?

推荐答案

响应格式文档表明,将返回XML响应。但是,如果我正确理解您的OP,则在通过浏览器发送时通过curl和XML响应发送纯文本响应。

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.

如果这是正确的,则您的浏览器可能会发送标题 - 可能是 接受 ,这会导致Amazon更改响应格式。尝试将以下内容添加到您的cURL设置中:

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' ]);

而不是 application / xml 尝试 application / json ,但再次基于文档我不希望会工作。

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

如果添加 Accept 头不工作,检查浏览器请求的标头,并复制所有在您的cURL设置中相关的。特别要注意的是,亚马逊MWS 文档应该发送 User-Agent ,但如果更改返回的格式会让我感到惊讶。

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.

这篇关于将亚马逊MWS结果获取到Json或Xml并进行详细说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆