使用c#实现企微推送excel文件,报错,代码如下,mediaid是postman获取的,response获取不到mediaid。
public async Task PostFile(string key, string filePath)
{
string idUrl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/upload_media?key=" + key + "&type=file";
string wxUrl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=" + key;
Console.WriteLine(filePath);
using (HttpClient client = new HttpClient())
{
var formDataContent = new MultipartFormDataContent();
var fileStream = new FileStream(filePath, FileMode.Open);
var fileContent = new StreamContent(fileStream);
formDataContent.Add(fileContent, "file", Path.GetFileName(filePath));
var response = await client.PostAsync(idUrl, formDataContent);
var result = await response.Content.ReadAsStringAsync();
var mediaId = "3nkJ81bXDllpLeTVB8l-MQiezr04Weq3FTL1t01FJKSZ_-l812G-Pn1jKfcWkRlDn";
//发送文件
var data = new
{
msgtype = "file",
file = new
{
media_id = mediaId
}
};
var wxResponse = await client.PostAsJsonAsync(wxUrl, data);
wxResponse.EnsureSuccessStatusCode();
return wxResponse;
}
}
}
}
麻烦各位大佬帮忙看一下谢谢
企业微信的问题建议到企业微信开发者中心提问:https://developer.work.weixin.qq.com/community/question