开发语言C#,
下面的代码可以解决如下问题:
- 企业微信,上传临时素材,报错: {"errcode":44001,"errmsg":"empty media data
[logid:]"}, - 文件上传后,格式丢失,后缀名丢失
- pdf不能在线预览了
根本就不需要设置很多请求头,不需要设置Content-Type:application/octet-stream
解决的代码:
csharp
string urlUpload="https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=VSHZ3SQ5lt4lX8m5vFXVoH2kIevJBO3ApY1MIEPjsHnBP7m9ZQ3GsNUIT1OVuQYcGhD00f7Kg_wC4JJTeWsGbQl_jpYZQK8-9TsumFURN8z4IpV3YaAZfES08ECr7guK0l_ZSGumlGbNRJIeNyetYsW6C-f-yuVyZGtPJBECAyPcZ7piavhueHTxMYbZ5ZiL42lEkHTd6RSr1sJ-5-0Itw&type=file";
WebClient webClient = new WebClient();
byte[] result = await webClient.UploadFileTaskAsync(urlUpload, "D:\\桌面\\测试文件1.pdf");
string json = Encoding.UTF8.GetString(result);