我想从具有C#的控制台应用程序向Web API请求POST操作。
控制台客户端的MyCode是:
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;
我从WebApi获得的代码是:
public ActionResult ReceiveInstructions(string instructions)
{
ApiFile apiFileObj = new ApiFile();
apiFileObj.ReceiveInstructions(instructions);
return View();
}
很简单...我的客户想向Web API发送一个字符串,WebAPI的控制器接收一个参数
ReceiveInstructions(字符串指令)
参数说明是字符串(JSON格式),原始信息是对象的集合。
当我尝试时..我的控制台基本上什么也不做。我需要更改一些东西吗?
非常感谢!