为什么我总是从Amazon Advertising API获得Bad Request 400?

时间:2014-01-13 15:13:03

标签: delphi soap amazon-web-services

我使用亚马逊广告API的delphi应用程序。 当我尝试获取ItemSearch时,我总是得到HTTP错误400 Bad Request。

重点在哪?

我的要求:

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
                   xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Header>
    <SOAP-ENV:Timestamp>2014-01-13T15:28:52Z</SOAP-ENV:Timestamp>
    <SOAP-ENV:AWSAccessKeyId>MYACCESSKEYID</SOAP-ENV:AWSAccessKeyId>
    <SOAP-ENV:Signature>rzNprsyKGKN2J4JZ8b/GvHqYPqs+kTJe0O5bjdnvHV8=</SOAP-ENV:Signature>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
    <ItemSearch xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
        <AWSAccessKeyId>MYACCESSKEYID</AWSAccessKeyId>
        <Request>
             <Keywords>Harry</Keywords>
             <SearchIndex>All</SearchIndex>
        </Request>
     </ItemSearch>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我创建了签名:

ts := '2014-01-13T15:28:52Z';
sig := GetBase64_HMAC_SHA256(MYSECRETKEY, 'ItemSearch' + ts);

我使用的Amazon SOAP URL:

rio.URL := 'https://webservices.amazon.de/onca/soap?Service=AWSECommerceService';

更新

我的delphi代码:

Cred := TSOAPCredentials.Create;
rio := THTTPRIO.Create(nil);
rio.OnAfterExecute := HTTPRIOAfterExecute;
rio.OnBeforeExecute := HTTPRIOBeforeExecute;
rio.SOAPHeaders.Send(cred);

rio.URL := 'https://webservices.amazon.com/onca/soap?Service=AWSECommerceService';

req := ItemSearchRequest.Create;
req.SearchIndex := 'All';
req.Keywords := 'Harry';
SetLength(ss, 1);
ss[0] := 'Small';
req.ResponseGroup := ss;
SetLength(reqs, 1);
reqs[0] := req;


isearch := ItemSearch.Create;
isearch.AWSAccessKeyId := MYACCESSKEYID;
isearch.Request := reqs;

res := GetAWSECommerceServicePortType(false, '', rio).ItemSearch(isearch);

1 个答案:

答案 0 :(得分:0)

<soap:Header
  xmlns:aws="http://security.amazonaws.com/doc/2007-01-01/">
  <aws:AWSAccessKeyId>AKIAIOSFODNN7EXAMPLE</aws:AWSAccessKeyId>
  <aws:Timestamp>2008-02-10T23:59:59Z</aws:Timestamp>
  <aws:Signature>SZf1CHmQnrZbsrC13hCZS061ywsEXAMPLE</aws:Signature>
</soap:Header>

您的标题应如上所示。我不知道你的情况会是什么“aws”。

在您的delphi代码中,rio.URL与您在问题中提到的soap URL不同。