如果我通过便签簿(AmazonServices/Scratchpad)向MWS提交请求,则成功,并且我能够查看成功请求的详细信息。特别是,请求上的时间戳看起来像这样:
&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‘},
时间戳与我在查询中放置的时间戳不同。为什么会发生这种情况?
发布于 2018-08-15 10:48:49
您的HTTP库已经在为您进行url编码,因此您需要对其进行双重编码。删除所有对encodeURIComponent()的引用,并正常格式化您的时间戳,使用:而不是%3A。观察生成的URL发生了什么变化。
为什么?重复URL编码是不安全的。
:通过一次传递就变成了%3A,但是通过第二次传递就变成了%253A,这是错误的。
https://stackoverflow.com/questions/51848063
复制相似问题