【问题标题】:C# MWS "the Content-MD5 HTTP header you passed for your feed did not match the Content-MD5 we calculated for your feed"C# MWS“您为供稿传递的 Content-MD5 HTTP 标头与我们为您的供稿计算的 Content-MD5 不匹配”
【发布时间】:2020-02-28 22:35:12
【问题描述】:

我正在尝试使用 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-commerce amazon-mws


    【解决方案1】:

    我在 Amazon Feeds Api 客户端库 > 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 哈希。

    【讨论】:

      【解决方案2】:

      根据您自己的答案,请确保在计算哈希之前将流位置设置回零。这应该可以解决您的问题:

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

      【讨论】:

        猜你喜欢
        • 2020-10-25
        • 1970-01-01
        • 1970-01-01
        • 2013-09-08
        • 1970-01-01
        • 2018-10-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多