在与请求匹配的控制器'Foo'上未找到任何操作

时间:2014-09-18 18:20:07

标签: c# android .net asp.net-web-api2

我无法使用android中的params调用web api。我可以不用params这样的问题可能是我如何发送params或我如何得到它们。

以下代码会出现此错误:

  

控制器上没有找到任何操作' Foo'与请求匹配。

的Android

ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("token", session.getAccessToken())); 

json = restClientService.getResponseAsJSON("http://192.168.2.242/WebApi/api/fbfeed/foo/", params);

-

private HttpResponse getWebServiceResponse(String URL,
        ArrayList<NameValuePair> params) {
    HttpResponse httpResponse = null;
    try {
        HttpParams httpParameters = new BasicHttpParams();

        // defaultHttpClient
        DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
        HttpPost httpPost = new HttpPost(URL);
        try {
            httpPost.setEntity(new UrlEncodedFormEntity(params));
        } catch (UnsupportedEncodingException e) {
        }
        httpResponse = httpClient.execute(httpPost);

配置

config.Routes.MapHttpRoute(name: "UserCreateApi", routeTemplate: "api/{controller}/{action}", defaults: new { action = "Foo" });

控制器

[AcceptVerbs("GET", "POST")]
public IHttpActionResult Foo([FromBody]string token)
{
     //some code
}

1 个答案:

答案 0 :(得分:0)

您的控制器是否继承自ApiController?你能从本地机器上的浏览器点击网址吗?