I have an endpoint like so:
[HttpPost("DoWork")]
public async Task<ActionResult> DoWork([FromForm] string name, [FromForm] string uri) {
...
}
From the other end how do I package and send that data, would it look something like this?
public void MyMethod(string name, string uri) {
Dictionary<string, string> packet = new Dictionary<string, string>();
packet.Add("name", name);
packet.Add("uri", uri);
var stringContent = new StringContent(JsonConvert.SerializeObject(packet), UTF8Encoding.UTF8, "application/json");
}
I accomplished it by using a RestRequest and adding in each parameter before sending the request:
RestClient rC = new RestClient(apiUrl);
RestRequest rr = new RestRequest(Method.POST);
rr.AddParameter("name", name);
rr.AddParameter("uri", uri);
RestResponse response = (RestResponse)await rC.ExecutePostAsync(rr);