// 调用接口上传文件
using (var client = new HttpClient())
{
using (var multipartFormDataContent = new MultipartFormDataContent())
{
var values = new[]
{
new KeyValuePair<string, string>("a", "3"),
new KeyValuePair<string, string>("c", "2"),
new KeyValuePair<string, string>("d", "2")
//other values
};
foreach (var keyValuePair in values)
{
multipartFormDataContent.Add(new StringContent(keyValuePair.Value),
String.Format("\"{0}\"", keyValuePair.Key));
}
multipartFormDataContent.Add(new ByteArrayContent(System.IO.File.ReadAllBytes(@"D:\test.jpg")),
"\"pic\"",
"\"test.jpg\""
C# HttpClient Post 参数同时上传文件 上传图片 调用接口
最新推荐文章于 2024-07-18 02:59:17 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)