Amazon Marketplace - MD5 content-header of XML in curl

454 views Asked by At

Trying to send through a request for _POST_PRODUCT_DATA_ using an XML feed and sending via cURL.

I'm getting the error;

SenderContentMD5DoesNotMatchthe Content-MD5 HTTP header you passed for your feed did not match the Content-MD5 we calculated for your feed

I've taken the output of our XML and passed it through the Amazon scratchpad and the MD5 result is the same as when I take the XML and run it through an online MD5 hash creator.

But when I output the result of md5($xml) on our server, the result is different - which I just cannot work out.

This is the code used to create the cURL request;

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $curlToSend);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$xml);
curl_setopt($ch,CURLOPT_HTTPHEADER, array("Content-Type: text/xml","Content-MD5: ".base64_encode(md5($xml)),"x-amazon-user-agent: MyScriptName/1.0"));
$result = curl_exec($ch);
curl_close($ch);

Where $curlToSend is the POST request and $xml obviously the built $xml code for the feed.

Can anyone help please!?

1

There are 1 answers

0
James Coin On

I think your XML string should be hashed in raw binary format for it to work with MWS.

base64_encode(md5($xml,true))