c# - 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 值不同。为什么会发生这种情况?
解决方案
我在 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 哈希。
推荐阅读
- python - 为什么 .isascii() 在 google colab 上不起作用?
- c# - 使用显式网络凭据从 .Net Core API 调用启用 SSO 的 API
- firebase - 多租户的 Firestore 规则?
- php - 仅获取前一小时添加的数据
- azure - 天蓝色是否有可能制定强制定价层的政策?
- python - 分配前引用的 /tweets 局部变量“searchtext”处的 UnboundLocalError
- python - Pypetteer 和 Asyncio:抓取页面,执行操作,抓取新页面
- ruby-on-rails - 使用用户名经过身份验证的设计根
- kotlin - 我想用 Vertx 发送一个文件部分图像,我想用 Postman 之类的代码复制这个案例
- python - 在 Python 中使用 Pillow 翻译图像并复制传入的像素