企业微信上传临时素材errcode:44001,errmsg:empty media data

发布时间:2024年01月16日

企业微信,上传临时素材,报错:
{“errcode”:44001,“errmsg”:“empty media data [logid:]”},
开发语言C#

重点代码:
formData.Headers.ContentType = new MediaTypeHeaderValue(“application/octet-stream”);

解决方案:

   string url = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=VSHZ3SQ5lt4lX8m5vFXVoH2kIevJBO3ApY1MIEPjsHnBP7m9ZQ3GsNUIT1OVuQYcGhD00f7Kg_wC4JJTeWsGbQl_jpYZQK8-9TsumFURN8z4IpV3YaAZfES08ECr7guK0l_ZSGumlGbNRJIeNyetYsW6C-f-yuVyZGtPJBECAyPcZ7piavhueHTxMYbZ5ZiL42lEkHTd6RSr1sJ-5-0Itw&type=file";

   var file = File.ReadAllBytes("D:\\桌面\\测试文件1.pdf");
   var fileContent = new ByteArrayContent(file, 0, file.Length);

   var handler = new HttpClientHandler();
   handler.ServerCertificateCustomValidationCallback = delegate { return true; };
   HttpClient client = new HttpClient(handler);

   client.Timeout = TimeSpan.FromSeconds(60);
   client.DefaultRequestHeaders.Add("mimeType", "multipart/form-data");
   client.DefaultRequestHeaders.Add("chart-set", "utf-8");

   MultipartFormDataContent formData = new MultipartFormDataContent();
   formData.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
   formData.Add(fileContent, "media", "1111.pdf");

   var response = await client.PostAsync(url, formData);
   string json = await response.Content.ReadAsStringAsync();
   /*
   错误:
   {"errcode":44001,"errmsg":"empty media data [logid:]"} 
   
   成功:
           {
                   "errcode": 0,
                   "errmsg": "ok",
                   "type": "file",
                   "media_id": "1UCCC4way6Adycbx_uq46hkNTOPYwC5Kfthw_-Pr6ClaPZKX6rKsyjntz_a0pGyJe",
                   "create_at": "1705401234"
             }
    */
文章来源:https://blog.csdn.net/u011511086/article/details/135632197
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。