2010-05-30 126 views
2

我使用的是亞馬遜的文檔ItemSearch一個簡單的例子,我得到一個奇怪的錯誤: 「遠程服務器返回了意外的響應:(400)錯誤的請求」亞馬遜API ItemSearch返回(400)錯誤的請求

這是代碼:

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

有什麼不對?

回答