How to pass an object (csv file) to HttpClient.PostAsync as a JSON body?

520 Views Asked by At

I am doing the test automation of a post request that takes a csv file (form data in postman) and returns a list. I want to add a csv file as an object in the body of the postasync request in my code. However, I would like to know how to add the path of csv file and how to let it point on the csv file. In postman, i just have to upload the csv file in the body of the post request without reading it.



string Folder = "\\Uploads\\630.csv";
FileStream fs = File.OpenRead(Folder);
var streamContent = new StreamContent(fs);
var fileContent = new ByteArrayContent(streamContent.ReadAsByteArrayAsync().Result);          

var ResponseList = HttpService.PostAsync<ListResponseModel>($"https://xxxxxxxxxxxxxx.com/sellers/1233/offers", fileContent, token).GetAwaiter().GetResult();
0

There are 0 best solutions below