我使用 Web api 自主机:
public class TestController : ApiController
{
[HttpPost]
public void Testp([FromBody]string title)
{
Console.WriteLine("Post");
}
}
这是简单的控制器,这是我的客户:
client.BaseAddress = new Uri("http://localhost:1010");
const string englishTitle = "TesteDelete";
var post = client.PostAsync("Test/Testp", new
{
title = englishTitle
}, new JsonMediaTypeFormatter());
var result = post.Result;
if (result.IsSuccessStatusCode)
{
}
else
{
string content = result.Content.ReadAsStringAsync().Result;
}
为什么我的结果是:
{StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Date: Sun, 21 Apr 2013 12:00:03 GMT
Server: Microsoft-HTTPAPI/2.0
Content-Length: 165
Content-Type: application/json; charset=utf-8
}}
我认为我的模型绑定器有一些错误