我的 MWS 请求中的时间戳有什么问题?

What is wrong with my timestamp in my MWS request?

如果我通过便签本向 MWS 提交请求(AmazonServices/Scratchpad), 它成功了,我可以查看成功请求的详细信息。特别是,请求上的时间戳如下所示:

&Timestamp=2018-08-14T18%3A30%3A02Z

如果我按原样使用这个时间戳,并尝试在我的代码中使用它来发出完全相同的请求,我会收到一个错误:

<Message>Timestamp 2018-08-14T18%3A30%3A02Z must be in ISO8601 
format</Message>\n 

这是我试图将其放入的函数:(一些字符在敏感参数中发生了变化)

exports.sendRequest = () => {

  return agent
    .post('https://mws.amazonservices.com/Products/2011-10-01')
    .query({
      AWSAccessKeyId: encodeURIComponent('BINAJO5TPTZ5TTRLNGQA'),
      Action: encodeURIComponent('GetMatchingProductForId'),
      SellerId: encodeURIComponent('H1N1R958BK8TTH'),
      SignatureVersion: encodeURIComponent('2'),
      Timestamp: '2018-08-14T18%3A30%3A02Z',
      Version: encodeURIComponent('2011-10-01'),
      Signature: encodeURIComponent(exports.generateSignature()),
      SignatureMethod: encodeURIComponent('HmacSHA256'),
      MarketplaceId: encodeURIComponent('ATVPDKIKX0DER'),
      IdType: encodeURIComponent('UPC'),
      'IdList.Id.1': encodeURIComponent('043171884536')
    })
    .then(res => {
      console.log('here is the response');
      console.log(res)
    })
    .catch(error => {
      console.log('here is the error');
      console.log(error);
    })
} 

更奇怪的是,这是请求发送到的路径:

path: '/Products/2011-10-01? 

AWSAccessKeyId=BINAJO5ZPTZ5YTTPNGQA&Action=GetMatchingProductForId&SellerId=H1N1R958ET8THH&SignatureVersion=2&Timestamp=2018-08-14T18%253A30%253A02Z&Version=2011-10-01&Signature=LwZn5of9NwCAgOOB0jHAbYMeQT31M6y93QhuX0d%252BCK8%253D&SignatureMethod=HmacSHA256&MarketplaceId=ATVPDKIKX0DER&IdType=UPC&IdList.Id.1= 043171884536'},

时间戳与我在查询中放置的时间戳不同。为什么会这样?

您的 HTTP 库已经在为您进行 url 编码,因此您在进行双重编码。删除对 encodeURIComponent() 的所有引用并正常格式化您的时间戳,使用 : 而不是 %3A。观察生成的 URL.

发生了什么

为什么? URL-重复编码不安全。

:传一遍就变成了%3A,传一遍就变成了%253A,这是错误的。