c# - 如何将多个参数传递给 web api

标签 c# json asp.net-web-api

我正在使用 fiddler 来测试我的请求..

我使用下面的 reuest 来调用我的 web api 方法..它工作正常。

 http://localhost:50079/Import/Test/abc

Type :Get

web api method:

       [ActionName("Test")]
        public bool getconnection(string id)
        {
            return true;
        }

如果我传递多个参数,我会收到错误消息:HTTP/1.1 404 Not Found

我用过:

http://localhost:50079/Import/Test/abc/cde

 Type :Get

 web api method:

           [ActionName("Test")]
            public bool getconnection(string id,string value)
            {
                return true;
            }

我不想使用任何路由...让我知道为什么如果我传递多个参数为什么无法识别它...

最佳答案

你必须指定一个匹配的路由

config.Routes.MapHttpRoute(
    name: "TestRoute",
    routeTemplate: "api/{controller}/{id}/{value}",
    defaults: new { id = RouteParameter.Optional, value = RouteParameter.Optional }
);

试试上面的

关于c# - 如何将多个参数传递给 web api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21950413/

相关文章:

javascript - 谷歌图表 : passing dates without using Date()?

javascript - 为什么预加载链接不适用于 JSON 请求?

json - HATEOAS中 "_embedded"的含义及用法

c# - Web API2 代理不重定向请求

c# - 在我们的服务器之间强制执行 TLS 1.2 后,Web Api 调用现在失败

c# - 在不调用外部 api 的情况下在 rest web API 的 Controller 内部查找客户端公共(public) IP 地址

c# - 拆分/合并具有 'nested' 外键引用的 shardlet

c# - 我可以在 Python3 中使用不同的代码点吗?

c# - DevExpress:XtraGridView 自定义列绑定(bind)

c# - 动态绑定(bind)到枚举