它取决于您的 Web API 服务的路由,但似乎您忘记了路由中的控制器名称。
默认情况下应该是
api/Account/Register
或者你的代码
client.BaseAddress = new Uri("http://localhost:22678/");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await client.PostAsync("api/Account/Register", ...body content...);
顺便说一句,HTTP 动词应该是 POST 而不是 GET,并且您应该在正文中放入一些内容。
您可以使用穿过身体PostAsync 方法参数称为 Content http://msdn.microsoft.com/en-us/library/hh138242%28v=vs.110%29.aspx。根据您的情况,最好的选择是使用对象内容 http://msdn.microsoft.com/en-us/library/system.net.http.objectcontent%28v=vs.118%29.aspx
您可以在此处找到有关如何使用对象的示例从 .NET 客户端调用 Web API http://www.asp.net/web-api/overview/web-api-clients/calling-a-web-api-from-a-net-client,引用这篇文章:
PostAsJsonAsync 是定义在中的扩展方法
System.Net.Http.HttpClientExtensions。它相当于
下列的:
var product = new Product() { Name = "Gizmo", Price = 100, Category = "Widget" };
// Create the JSON formatter.
MediaTypeFormatter jsonFormatter = new JsonMediaTypeFormatter();
// Use the JSON formatter to create the content of the request body.
HttpContent content = new ObjectContent<Product>(product, jsonFormatter);
// Send the request.
var resp = client.PostAsync("api/products", content).Result;