【发布时间】: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