【发布时间】:2017-11-01 14:01:25
【问题描述】:
我只想在 asp.net mvc 中发布 Webapi 方法,发布操作方法看起来像
[HttpPost]
[Route("api/agency/Dashboard")]
public HttpResponseMessage Index(getCookiesModel cookies)
{
//code here
}
我正在发送这样的帖子请求
string result = webClient.DownloadString("http://localhost:11668/api/agency/dashboard?cookies=" + cookies);
和 getCookiesModel
public class getCookiesModel
{
public string userToken { get; set; }
public string firstName { get; set; }
public string lastName { get; set; }
public long userId { get; set; }
public string username { get; set; }
public string country { get; set; }
public string usercode { get; set; }
}
但是找不到这个返回 404 页面。 请帮我解决这个问题。
【问题讨论】:
-
DownloadString是一个 GET 请求,由于该操作需要一个 POST,因此您可以看到问题所在。 -
请问如何解决。
-
呃...从 Post 更改为 Get?
-
@DumpsterDiver:删除
[HttpPost]注释,以便可以从 GET 请求中使用该操作。
标签: c# asp.net-web-api routing