1
我正在使用WebApi.SelfHost但我的帖子始終爲空。 我嘗試了所有可以找到的解決方案,但都沒有成功。c#WebApi.SelfHost post is null
我被這個問題困住了好幾個小時。 我嘗試了所有我能找到的解決方案,但都沒有成功。
我知道這個問題已經被問到。但我已經嘗試過所有的解決方案,但他們都沒有工作。而且他們沒有使用自己的主機。
這是我的代碼。
class Program
{
static void Main(string[] args)
{
var config = new HttpSelfHostConfiguration("http://localhost:8080");
config.Routes.MapHttpRoute(
"API Default", "api/{controller}/{action}/{id}",
new { id = RouteParameter.Optional });
using (HttpSelfHostServer server = new HttpSelfHostServer(config))
{
server.OpenAsync().Wait();
Console.WriteLine("Press Enter to quit.");
Console.ReadLine();
}
}
}
public class testController : ApiController
{
[HttpPost]
public string test(int id ,[FromBody]string value)
{
return value;
}
}
我使用Advanced REST client測試
這裏是我的結果
非常感謝你 –