Amazon API ItemSearch返回(400)错误请求

时间:2010-05-30 12:25:16

标签: amazon-web-services amazon-product-api

我正在使用AmazonSearch文档中的一个简单示例,我收到一个奇怪的错误: “远程服务器返回了意外的响应:(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();

有什么问题?

1 个答案:

答案 0 :(得分:4)

您收到此邮件是因为您的请求未签名。从2009年8月开始,所有请求必须签署。

在这里您可以看到有关如何签署亚马逊请求的示例: http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2480&categoryID=14