调试Amazon提交是很麻烦的,因为无论您做什么错误,Ama只返回相同的无意义错误消息:
<Error>
<Type>Sender</Type>
<Code>InvalidParameterValue</Code>
<Message>Either Action or Operation query parameter must be present.</Message>
</Error>我100%肯定我建立了正确的StringToSign以及计算HMAC- that 256等。我花了几个星期收集和采用了一堆有用的功能,用于散列、签名、base64ing等MWS请求。它们都是用纯Pascal编写的,它们都在订单和产品API上进行了测试。
现在,当谈到提要API时,我被困在了上面的错误上。所有参数都等于由MWS Scratchpad生成的参数。我测试了MWS生成的提交StringToSign,但是没有结果。
到目前为止,我注意到的是:生成的标题的数量/值与我的应用程序之间存在差异。
Scratchpad生成以下标题(至少显示它们):
Host: mws.amazonservices.ca
x-amazon-user-agent: AmazonJavascriptScratchpad/1.0 (Language=Javascript)
Content-Type: text/xml我的应用程序使用Indy (在XE4中) TIdHTTP来提出请求。当亚马逊返回上述错误时,Request.RawHeaders.Text包含以下内容:
Content-Length: 251
x-amazon-user-agent: MyApp/1.1(Language=Delphi;Platform=Windows7)
Content-Type: text/xml
Host: mws.amazonservices.ca
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: identity
User-Agent: MyApp/1.1(Language=Delphi;Platform=Windows7)看起来,在默认情况下,额外的标头被添加到Request对象中。我的第一个问题是:这些额外的标题理论上会对行为产生影响吗?也就是说,他们能成为表演的挡箭牌吗?
我的第二个问题:在Indy HTTP.Request中,是否有任何选择来更改默认标题列表?为了继续调试,我宁愿排除额外的头,以查看请求是否有效。
更新:(SignedString)
AWSAccessKeyId=<AWSAccessKeyId>
&Action=GetFeedSubmissionList
&Merchant=<MerchantId>
&SignatureMethod=HmacSHA256
&SignatureVersion=2
&Timestamp=2015-07-26T09%3A04%3A59Z
&Version=2009-01-01
&Signature=1OI0PVgL3uh5sFXxjCzaaWEwGmW6h5e0dgLUFkPgoXg%3D更新:(TIdLogFile提供的完整HTTP请求/响应)
Stat Connected.
Sent 28.07.2015 12:28:11:
POST / HTTP/1.1<EOL>
Content-Type: text/xml; charset=us-ascii<EOL>
Content-Length: 279<EOL>
x-amazon-user-agent: MyAppNameAndVer<EOL>
Host: mws.amazonservices.ca<EOL>
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8<EOL>
Accept-Encoding: identity<EOL>
User-Agent: Mozilla/3.0 (compatible; Indy Library)<EOL><EOL>
Sent 28.07.2015 12:28:11:
AWSAccessKeyId=<AWSAccessKeyId>
&Action=GetFeedSubmissionList
&MWSAuthToken=<AWSAuthToken>
&Merchant=<MerchantId>
&SignatureMethod=HmacSHA256
&SignatureVersion=2
&Timestamp=2015-07-28T10%3A28%3A09Z
&Version=2009-01-01
&Signature=I6euLIiVDzjZ8bbdtF840K0TJCkGh4NrUbQPtQtu78A%3D
Recv 28.07.2015 12:28:11:
HTTP/1.1 400 Bad Request<EOL>
Date: Tue, 28 Jul 2015 10:28:10 GMT<EOL>
Server: AmazonMWS<EOL>
x-mws-request-id: 7e63280d-1db5-4d10-af40-587747d032a8<EOL>
x-mws-timestamp: 2015-07-28T10:28:11.048Z<EOL>
x-mws-response-context: OmAlguEmW20QT07uIdb9d25xkX+JSS7uFr1rDvXIoqXMvbUFzUMt1b5Xl2WzDaJszbwr25N/J4c=<EOL>
Content-Type: text/xml<EOL>
Content-Length: 324<EOL>
Vary: User-Agent<EOL>
nnCoection: close<EOL><EOL>
<?xml version="1.0"?><LF><ErrorResponse xmlns="https://mws.amazonservices.com/"><LF> <Error><LF> <Type>Sender</Type><LF> <Code>InvalidParameterValue</Code><LF> <Message>Either Action or Operation query parameter must be present.</Message><LF> </Error><LF> <RequestID>7e63280d-1db5-4d10-af40-587747d032a8</RequestID><LF></ErrorResponse><LF>
Stat Disconnected.请注意:为了方便您在<EOL>后添加CRs,我格式化了响应。
混淆的nnCoection头在这里解释:nnCoection HTTP报头
我的问题现在解决了。以下是我要向没有违反社区标准的人致谢;)
Days := 1;
repeat
IsSuccessful := DebugAmazonFeedSubmissionProc;
Inc(Days);
until IsSuccessful or (Days = 14);
if not IsSuccessful then
begin
AskTheGods(@StackOverflow);
Sleep(1000); // ...wake up and drink a cup'o'tea :)
Expert := TRemyLebeau.Create('delphi');
try
Expert.ReviewTheCode;
Expert.GetTheJobDone;
finally
// You may dispose the instance here,
// but the Class is one of the most valuable assets of the Community.
// Thank you, Remy!
end;
end;发布于 2015-07-28 15:32:17
您的请求Content-Type头错误。您已经将其设置为text/xml; charset=us-ascii,但实际上并不是首先发送XML数据。根据MWS的Content-Type文档,您需要将TIdHTTP.Request.ContentType (通过TIdHTTP.Request.ContentType属性)设置为application/x-www-form-urlencoded。
TStrings版本的TIdHTTP.Post()将为您设置ContentType,但是您使用的是TStream版本,因此必须手动设置ContentType。在这种情况下,我建议您切换到TStrings版本,并让它为您处理表单字段的编码:
var
PostData: TStringList;
begin
PostData := TStringList.Create;
try
PostData.Add('AWSAccessKeyId=<AWSAccessKeyId>');
PostData.Add('Action=GetFeedSubmissionList');
PostData.Add('MWSAuthToken=<AWSAuthToken>');
PostData.Add('Merchant=<MerchantId>');
PostData.Add('SignatureMethod=HmacSHA256');
PostData.Add('SignatureVersion=2');
PostData.Add('Timestamp=2015-07-28T10:28:09Z'); // <-- NOT percent encoded yet!
PostData.Add('Version=2009-01-01');
PostData.Add('Signature=I6euLIiVDzjZ8bbdtF840K0TJCkGh4NrUbQPtQtu78A='); // <-- NOT percent encoded yet!
IdHTTP1.Request.CustomHeaders.Values['x-amazon-user-agent'] := 'MyAppNameAndVer';
IdHTTP1.Post('http://mws.amazonservices.ca', PostData);
finally
PostData.Free;
end;
end;https://stackoverflow.com/questions/31630075
复制相似问题