2015-09-02 59 views
2

我是自承載Web API。任何從我的集成測試中獲得的要求都能正常工作。但是,任何POST請求都會拒絕連接。我似乎無法處理髮生的事情。HTTP POST在OWIN自主Web API中不起作用

錯誤消息

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!"; 
} 

回答

1

我有同樣的問題,並發現在您的方法參數之前有必要使用[FromBody]屬性。在這種情況下,它可以解析請求負載,你可以達到你的方法

希望幫助

1

難道你米西ng a/on:

using (WebApp.Start<App_Start.TestConfiguration>("http:/localhost:8216")) 

它應該是http://localhost:8216

+0

是啊,這讓我通過它的一部分。現在我有一個400錯誤:( – Mateo