.net core HttpClient请求体FormData类型,字段key是pictures[],要怎么写


回答

你那个 RestApi 是个啥?

如果是 System.Net.Http.HttpClient 上传 FormData 的话,应该像这样:

using System;

using System.Net.Http;

using (var httpClient = new HttpClient())

using (var httpRequest = new HttpRequestMessage(HttpMethod.Post, "/upload"))

{

var formData = new MultipartFormDataContent();

formData.Add(new StringContent("mywechat"), "wechat");

formData.Add(new StringContent("mypicture1,mypicture2"), "pictures[]");

formData.Add(new StringContent("mytitle"), "title");

httpRequest.Content = formData;

using (var httpResponse = await httpClient.SendAsync(httpRequest))

{

httpResponse.EnsureSuccessStatusCode();

}

}

P.S. 头一次见到这么奇葩的接口字段。

以上是 .net core HttpClient请求体FormData类型,字段key是pictures[],要怎么写 的全部内容, 来源链接: utcz.com/a/23566.html

回到顶部