I am trying send a csv file and parameters to a http API and am struggling to debug what is going wrong.
For POST requests that require parameters only (no csv file) then I can successfully do this:
HttpContent upload = new FormUrlEncodedContent(new Dictionary<string, string> { { "name", "myName" }});
HttpResponseMessage uploadResponse = await client.PostAsync("api/datasets", upload);
For POST requests that require parameters and a csv file I am using MultipartFormDataContent:
var content = new MultipartFormDataContent();
HttpContent upload = new FormUrlEncodedContent(new Dictionary<string, string> { { "name", "myName" }});
content.Add(upload);
byte[] csvBytes = File.ReadAllBytes("myfile.csv");
var csvContent = new ByteArrayContent(csvBytes);
content.Add(csvContent, "csvfile", "datafile.csv");
HttpResponseMessage uploadResponse = await client.PostAsync("api/datasets", content);
However, the sever is now returning a message saying I have not specified the "name" parameter. What am I missing? How do I submit the parameters correctly?