mercredi 1 juillet 2015

ContentMD5Missing - Amazon Webservice

I'm trying to post to Feed -> SubmitFeed.

However the exception I receive back is:

you must pass a Content-MD5 HTTP header for your feed so we can be sure it was not corrupted (e.g. dropped a 0 from a price) before we process it

What I don't understand is the documentation states that it is optional so unsure why I am receiving this. Plus I am actually passing something through.

XML

  <?xml version="1.0" encoding="UTF-8" ?> 
- <AmazonEnvelope xmlns:xsd="http://ift.tt/tphNwY" elementFormDefault="qualified" schemaLocation="amzn-base.xsd">
- <Header>
  <DocumentVersion>1</DocumentVersion> 
  <MerchantIdentifier>A1ddWU5JfffWJEddV9Xf668B</MerchantIdentifier> 
  </Header>
  <MessageType>Product</MessageType> 
  <PurgeAndReplace>false</PurgeAndReplace> 
- <Message>
  <MessageId>1</MessageId> 
  <OperationType>Update</OperationType> 
  </Message>
- <Product>
  <SKU>3308ff6-01</SKU> 
  </Product>
  </AmazonEnvelope>

How I attach the Body/Header

    var request = Helper.CreateWebRequest(xmlRequest.Config, genericparameters, signatureHelpers);

    request.Headers.Add("x-amazon-user-agent", amazonHostAgent);
    request.Method = "POST";
    request.ContentType = amazonConfig.ContentType;
    request.Timeout = 50000;

    Helper.AddXmlDocumentToRequest(xmlRequest.XmlDocument.InnerXml, request);

    public static void AddXmlDocumentToRequest(string xmlDocument, WebRequest request)
    {
        var bytes = Encoding.ASCII.GetBytes(xmlDocument);
        request.ContentLength = bytes.Length;
        var requestStream = request.GetRequestStream();

        request.Headers.Add("Content-MD5", GetMd5HashFromStream(bytes));

        requestStream.Write(bytes, 0, bytes.Length);
        requestStream.Close();
    }

    public static string GetMd5HashFromStream(byte[] bytes)
    {
        using (var md5 = MD5.Create())
        {
            var hash = md5.ComputeHash(bytes);
            return Convert.ToBase64String(hash);
        }
    }

Within the request when I drill down to Headers I have the following:

{x-amazon-user-agent: MWSApplication/1.0 (Language=c#)
Content-Type: text/xml
Host: mws.amazonservices.co.uk
Content-Length: 478
Expect: 100-continue
Content-MD5: 1xLxj5Y+WVsAVR9BbQfzQA==

}

When I run the xml through scratchpad it returns the same Content-MD5: 1xLxj5Y+WVsAVR9BbQfzQA==

Am I doing something wrong?

Thanks,

Clare




Aucun commentaire:

Enregistrer un commentaire