【问题标题】:API request to MVC Web API fetting a 400 Bad Request response对 MVC Web API 的 API 请求得到 400 Bad Request 响应
【发布时间】:2012-08-21 12:29:53
【问题描述】:

谁能看到我对我的 API 的这个 GET 请求做错了什么(来自 Fiddler):

http://localhost:51488/api/searchapi/Demo&Dte=2012-08-25&Nts=1

它返回一个 400 Bad Request HTTP 响应。

我的路线是:

routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

我的 SearchAPIController.cs 是:

   // GET api/searchapi
    public IEnumerable<RatesViewModel> Get(string id, DateTime Dte, int Nts)
    {

所以我希望:

id = "Demo"
Dte = 2012-08-25
Nts = 1

但它似乎没有达到控制器的程度。

感谢您的帮助,

标记

【问题讨论】:

    标签: jquery asp.net asp.net-mvc asp.net-web-api


    【解决方案1】:
    http://localhost:41645/api/searchapi/Demo&Dte=2012-08-25&Nts=1
    

    应该是:

    http://localhost:41645/api/searchapi/Demo?Dte=2012-08-25&Nts=1
    

    请注意,查询字符串参数以问号 (?) 开头。

    【讨论】:

    • 嗨达林 - 再次帮助我......非常感谢你 - 在允许时将接受作为答案。标记
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-28
    • 2017-11-22
    相关资源
    最近更新 更多