Is there a way to reorder the data sent in a multipart form POST request?

Viewed 12

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?

0 Answers
Related