简体   繁体   中英

Amazon API ItemSearch returns (400) Bad Request

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."

This is the code:

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

What is wrong?

You receive this message because your request is not signed. Starting from August 2009 all requests must be signed.

Here you can see at the example about how to sign amazon requests: http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2480&categoryID=14

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM