首页 > 解决方案 > C# MWS“您为供稿传递的 Content-MD5 HTTP 标头与我们为您的供稿计算的 Content-MD5 不匹配”

问题描述

我正在尝试使用 Amazon Feeds API > SubmitFeed 操作。

我将请求的 FeedContent 设置为由 XmlWriter 创建的内存流。

请求的 ContentMD5 变量设置为:

 request.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(request.FeedContent);

我正在使用亚马逊 MWS Feeds Api 客户端库(https://developer.amazonservices.com/doc/bde/feeds/v20090101/cSharp.html

我没有更改代码。当我调用 MarketplaceWebService.SubmitFeed 时,我收到此错误:

“您为供稿传递的 Content-MD5 HTTP 标头与我们为您的供稿计算的 Content-MD5 不匹配”

亚马逊说:他们计算的 MD5 和我的 MD5 值不同。为什么会发生这种情况?

标签: c#e-commerceamazon-mws

解决方案


我在 Amazon Feeds Api Client Library > MarketplaceWebServiceClient.cs 文件中添加了一个方法:

 public static string CalculateContentMD5(byte[] content)
 {
        MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
        byte[] hash = provider.ComputeHash(content);
        return Convert.ToBase64String(hash);
 }

有一个

public static string CalculateContentMD5(Stream content) 

功能,但它不能正常工作。

使用 byte[] 而不是 Stream 来计算 MD5 哈希。


推荐阅读