jeudi 3 septembre 2015

.Net Error 400- Bad Request when posting request to Amazon MWS

Here is the code I am using to retrieve orders from Amazon (I changed sensitive data to xxx):

string key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
        string message = "POST" + "\n" +
                         "mws.amazonservices.com" + "\n" +
                         "/Orders/2013-09-01" + "\n" +
                         "AWSAccessKeyId=xxxxxxxxxxxxxxxx&Action=ListOrders&CreatedAfter=2015-08-18T04%3A00%3A00Z&MarketplaceId.Id.1=ATVPDKIKX0DER&OrderStatus.Status.1=Shipped&SellerId=xxxxxxxxxxxx&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2015-09-01T17%3A46%3A44Z&Version=2013-09-01";
        string signature = CreateToken(message, key);

        NameValueCollection collection = new NameValueCollection();
        collection.Add("AWSAccessKeyId", "xxxxxxxxxxxxxxxxx");
        collection.Add("Action", "ListOrders");
        collection.Add("SellerId", "xxxxxxxxxxxxxxx");
        collection.Add("SignatureVersion", "2");
        collection.Add("Timestamp", "2015-09-03T02%3A21%3A43Z");
        collection.Add("Version", "2013-09-01");
        collection.Add("Signature", signature);
        collection.Add("SignatureMethod", "HmacSHA256");
        collection.Add("CreatedAfter", "2015-08-18T04%3A00%3A00Z");
        collection.Add("MarketplaceId.Id.1", "ATVPDKIKX0DER");
        collection.Add("OrderStatus.Status.1", "Shipped");

        using (WebClient client = new WebClient())
        {
            byte[] response =
            client.UploadValues("http://ift.tt/PeLt2L","POST",  collection);

            string result = Encoding.UTF8.GetString(response);
        }

I am getting an error 400- bad request from server. I believe the parameters are in the proper order (if that's necessary).




Aucun commentaire:

Enregistrer un commentaire