【问题标题】:Why I always get Bad Request 400 from Amazon Advertising API?为什么我总是从亚马逊广告 API 收到错误请求 400?
【发布时间】:2014-01-14 13:13:16
【问题描述】:

我有使用亚马逊广告 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);

我使用的亚马逊 SOAP URL:

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

更新:

我的德尔福代码:

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

【问题讨论】:

  • 感谢 Mason,在遇到错误一天后我有点发疯了。
  • 你能不能修改你的代码来得到soap故障。我使用soap ui在您的配置中尝试了此api,但由于soap错误“请求必须包含参数签名”而出现错误。所以我尝试按照我的回答中提到的那样发送请求并猜猜是什么,我收到了回复,例如您的时间戳已过期或您的访问密钥无效,例如这些消息。

标签: delphi soap amazon-web-services


【解决方案1】:
<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 不同。

【讨论】:

  • 谢谢,我使用了 REST 格式。肥皂没有工作太久。
猜你喜欢
  • 2012-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多