Amazon API ItemSearch返回(400)错误的请求 [英] Amazon API ItemSearch returns (400) Bad Request
问题描述
我正在使用Amazon文档中的一个简单示例进行ItemSearch,但出现一个奇怪的错误: 远程服务器返回了意外的响应:(400)错误的请求."
I'm using a simple example from Amazon documentation for ItemSearch and I get a strange error: "The remote server returned an unexpected response: (400) Bad Request."
这是代码:
public static void Main()
{
//Remember to create an instance of the amazon service, including you Access ID.
AWSECommerceServicePortTypeClient service = new AWSECommerceServicePortTypeClient(new BasicHttpBinding(),
new EndpointAddress(
"http://webservices.amazon.com/onca/soap?Service=AWSECommerceService"));
AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient(
new BasicHttpBinding(),
new EndpointAddress("http://webservices.amazon.com/onca/soap?Service=AWSECommerceService"));
// prepare an ItemSearch request
ItemSearchRequest request = new ItemSearchRequest();
request.SearchIndex = "Books";
request.Title = "Harry+Potter";
request.ResponseGroup = new string[] { "Small" };
ItemSearch itemSearch = new ItemSearch();
itemSearch.Request = new ItemSearchRequest[] { request };
itemSearch.AWSAccessKeyId = accessKeyId;
// issue the ItemSearch request
try
{
ItemSearchResponse response = client.ItemSearch(itemSearch);
// write out the results
foreach (var item in response.Items[0].Item)
{
Console.WriteLine(item.ItemAttributes.Title);
}
}
catch(Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(e.Message);
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Press any key to quit...");
Clipboard.SetText(e.Message);
}
Console.ReadKey();
怎么了?
推荐答案
您收到此消息是因为您的请求未签名.从2009年8月开始,必须签署所有请求.
You receive this message because your request is not signed. Starting from August 2009 all requests must be signed.
在这里您可以看到有关如何签署亚马逊请求的示例: http://developer.amazonwebservices.com/connect/entry. jspa?externalID = 2480& categoryID = 14
Here you can see at the example about how to sign amazon requests: http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2480&categoryID=14
这篇关于Amazon API ItemSearch返回(400)错误的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!