I want to request a POST action from a console application with C# to Web API.
MyCode from Console Client is:
consoleClient = new HttpClient();
consoleClient.BaseAddress = new Uri("http://localhost:40659/home/receiveinstructions");
consoleClient.DefaultRequestHeaders.Accept.Clear();
consoleClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response =
await consoleClient.PostAsJsonAsync("http://localhost:40659/home/receiveinstructions", EventFile.eventFileList);
response.EnsureSuccessStatusCode();
return response.Headers.Location;
My code from WebApi is:
public ActionResult ReceiveInstructions(string instructions)
{
ApiFile apiFileObj = new ApiFile();
apiFileObj.ReceiveInstructions(instructions);
return View();
}
Its simple... my client want to send a string to web API, the controller from WebAPI receive one parameter
ReceiveInstructions(string instructions)
Parameter instructions is string (JSON format) original info is a collection of objects.
When I'm try.. my console basically don't do anything. Do i need to change something?
Thanks a lot!!