1

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();
Wiss
  • 11
  • 3
  • What does your API controller method look like? Does it accept a model? – JamesS Jan 20 '22 at 13:20
  • I don't have an api controller method. should I have one ? – Wiss Jan 20 '22 at 13:37
  • I mean you must be calling an api method yeah? I'm guessing called `sellers` or `offers`. Does it accept a model? – JamesS Jan 20 '22 at 13:41
  • I didn't get it. What do you mean by a model ? I am doing the automation of the api test. so I don't really care about sellers and offers. instead of doing the call from postman i do it automatically with my code i just prepare the body (it's file content in this case) – Wiss Jan 20 '22 at 13:52
  • I mean, you're obviously calling an API endpoint yeah? It's a `POST` so you've obviously sending it something. What are you sending it? Is it an object? – JamesS Jan 20 '22 at 13:52
  • i have to get the access token first, prepare the body next and do the call. var ClientId = "xxxxxxxxxxx"; var ClientSecret = "xxxxxxxxxxxxxxxx"; var token = KeycloakService.GetTokenAsync(ClientId, ClientSecret).GetAwaiter().GetResult(); – Wiss Jan 20 '22 at 13:54
  • Ok I get your point. I am trying to send a csv file. – Wiss Jan 20 '22 at 13:55
  • Can you change your API endpoint or is it third party? – JamesS Jan 20 '22 at 14:01
  • i can change the API endpoint – Wiss Jan 20 '22 at 14:11
  • The problem that I have is with content body and not with the endpoint – Wiss Jan 20 '22 at 14:31

0 Answers0