H5W3
当前位置:H5W3 > 其他技术问题 > 正文

.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. 头一次见到这么奇葩的接口字段。

本文地址:H5W3 » .net core HttpClient请求体FormData类型,字段key是pictures[],要怎么写

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址