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测试
这里是我的结果
非常感谢你 –