0

I am making a request to an external API which needs data in a multipart form to be sent in a specific order.

I have two parameters for the request, one is a JsonParameter and the other is a file.

The issue I am having is I need the JsonParameter to come first in the form data request but cannot find a way to do that currently. I have tried simply changing the order I add to the request but this doesn't seem to affect the order when the request is sent.

This is my current code for the request:

var client = new RestClient(baseUrl);
var request = new RestRequest(endpoint, Method.Post);
request.AlwaysMultipartFormData = true;

var json = JsonConvert.SerializeObject(profile);
var jsonParam = new JsonParameter("profile", profile);
request.AddParameter(jsonParam);

var filename = "test.txt";
var bytes = File.ReadAllBytes(filepath);
request.AddFile("file", bytes, filename, "text/plain");


request.AddHeader("X-auth-token", bearerToken);

var res = await client.ExecuteAsync(request);

Is this possible using restsharp so that the JsonParameter will always come first in the request?

  • I think something is wrong at the other end. Ask them why they want this order. Because I think it should not matter – Vivek Nuna Sep 20 '22 at 09:41
  • @viveknuna I completely agree with you, it shouldn't have to be ordered like this but was just trying to see if this would be possible as I don't think changes to their API will happen quickly but will open a ticket with them anyway. – Corey Hayward Sep 20 '22 at 10:02

0 Answers0