System.IO.InvalidDataException: Missing content-type boundary.

  • 开发语言:C#
  • 框架集:.NET 8

使用HttpClient上传文件报错:System.IO.InvalidDataException: Missing content-type boundary.

解决代码:

  [TestMethod]
  public async Task Test3()
  {
      string fileName = "132.pdf";
      HttpClient httpClient = new HttpClient();         
      ByteArrayContent byteArrayContent = new ByteArrayContent(File.ReadAllBytes("D:\\桌面\\测试文件1.pdf"));       
      MultipartFormDataContent formData = new MultipartFormDataContent();     
      formData.Add(byteArrayContent, "file", fileName);

      //文章详情pdf,上传文件到即时通里面,作为临时素材;
      var response = await httpClient.PostAsync("http://xx.gg.com/upload", formData);
      string json = await response.Content.ReadAsStringAsync();
  }

你可能感兴趣的:(C#,c#,HttpClient)