【发布时间】:2015-09-02 15:34:45
【问题描述】:
我自己托管一个 Web API。我从集成测试中提出的任何 Get Reqeust 都可以正常工作。但是,任何 POST 请求都会引发连接被拒绝。我似乎无法掌握正在发生的事情。
错误信息
system.Net.HttpRequestException: An error occured while sending the request to the remote server. SocketException: no connection could be made because the target machine actively refused.
代码
using (WebApp.Start<App_Start.TestConfiguration>("http:/localhost:8216"))
{
var client = new HttpClient();
client.BaseAddress = new System.Uri("http://127.0.0.1:8216");
var response = await client.PostAsync("/api/MyController", new StringContent("something"));
}
控制器
public string Post(string value)
{
return "Hello!";
}
【问题讨论】:
标签: c# .net asp.net-web-api2 owin self-hosting