private string uploadIcpMedia(HttpContext context)
{
string accessToken = context.Request.QueryString["access_token"];
string type = context.Request.Form["type"];
string certificateType = context.Request.Form["certificate_type"];
string icpOrderField = context.Request.Form["icp_order_field"];
HttpPostedFile file = context.Request.Files["media"];
byte[] mediaBytes = ReadFileBytes(file);
if (!string.IsNullOrEmpty(accessToken) && !string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(icpOrderField))
{
if (file != null)
{
string apiUrl = $"https://api.weixin.qq.com/wxa/icp/upload_icp_media?access_token={accessToken}";
var httpClient = new HttpClient();
string boundary = Guid.NewGuid().ToString("N");
var content = new MultipartFormDataContent(boundary);
//content.Headers.ContentType = MediaTypeHeaderValue.Parse($"multipart/form-data;boundary={boundary}");
content.Add(new StringContent(type), "type");
content.Add(new StringContent(certificateType), "certificate_type");
content.Add(new StringContent(icpOrderField), "icp_order_field");
content.Add(new ByteArrayContent(mediaBytes), "media", $"\"{file.FileName}\"");
string requestString = content.ReadAsStringAsync().Result;
var postResult = httpClient.PostAsync(apiUrl, content).Result;
string result = postResult.Content.ReadAsStringAsync().Result;
return result;
}
else
{
return "No media data provided";
}
}
else
{
return "Missing required parameters: access_token, type, and/or icp_order_field";
}
}
请求返回{ "errcode": 41005, "errmsg": "media data missing, hint: [2c54ff85-e7ab-4e0c-8f37-385218c0a87d] rid: 655825b1-49c05972-19528b29"},之前看到一个帖子,说把boundary的引号去掉就可以,就是代码里注释掉的那一行,但是那只适用form-data只有上传media一个参数。在这个上传备案媒体材料接口,form-data上传多个参数,把boundary的引号去掉就会报missing parameter的错,但是注释掉就会报错media data missing。到底应该怎么解决,我使用的是.net4.8。
建议参考文档仔细检查下参数上传是否有误
请问有解决么
请问,解决了吗 我也是c# 一直提示media data missing