HttpClient Multipart Form Post in C#

前端 未结 4 2129
既然无缘
既然无缘 2020-12-12 22:24

I\'m trying to do a multipart form post using the HttpClient in C# and am finding the following code does not work.

Important:

var j         


        
4条回答
  •  轮回少年
    2020-12-12 22:55

    string path = @"C:\New folder\Test.pdf";  // **ANY FILE**
                                
    var formContent = new MultipartFormDataContent
    {
         { new ByteArrayContent(File.ReadAllBytes(path)), "file", Path.GetFileName(path) }
    };
    
    var client = new HttpClient();
    var response = client.PostAsync(_configuration["Url"], formContent).Result;
    

提交回复
热议问题