URL连接codeD结肠400错误的请求解析 [英] URL encoded colon resolves in 400 Bad Request

查看:120
本文介绍了URL连接codeD结肠400错误的请求解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在400这个网址的决心 - 错误的请求。

Why does this url resolve in 400 - Bad Request?

的http://本地主机:2785 / API /股票/ Web.App.QuotesReaders /搜索= SE%3Aabb

我的环境是Visual Studio 2010中,MVC 4和所使用的控制器是WebApiController。

My environment is Visual Studio 2010, MVC 4 and the controller used is a WebApiController.

在%3A是一个URL-CN codeD冒号。

The %3A is an URL-encoded colon.

SOLUTION

这适用于某些原因:

http://localhost:2785/api/ticker?className=Web.App.QuotesReaders&search=se%3Aabb

...这意味着,我不能指定的global.asax.cs这条路线:

... which means, I couldn't specify this route in global.asax.cs:

/api/ticker/{className}/{search}

...这也...

... nor this ...

/api/ticker/{className}/search={search}

...但是这...

... but this ...

/api/ticker

有关更多信息:<一href=\"http://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaughtyThingsInTheASPNETIISRequestURL.aspx\" rel=\"nofollow\">http://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaughtyThingsInTheASPNETIISRequestURL.aspx

推荐答案

看来,ASP.net不前,让冒号?在URL,即使它是连接codeD为%3A。

It seems that ASP.net does not allow colons before the '?' in an URL, even if it is encoded as %3A.

例如,这些将无法正常工作

For example, these won't work

http://foo.org/api/persons/foo:bar
http://foo.org/api/persons/foo%3abar

但这个工程:
http://foo.org/api/persons?id=foo%3abar

在所有案例中,我们希望ASP.NET MVC传递富:酒吧作为一个id参数,正确地去codeD。我只是MVC4测试这一点,它似乎工作。这是烦人,不接受问号之前的URL编码虽然,但我敢肯定有一个很好的理由。可能把一切都问号问号后面一个有效的URL和任何参数之前。

In all examples, we would expect ASP.NET MVC to pass "foo:bar" as an id argument, properly decoded. I just tested this with MVC4 and it seems to work. It is annoying that it doesn't accept the URL encoding before the question mark though, but I'm sure there is a good reason for it. Probably to keep everything before the question mark a valid URL and any arguments after the question mark.

这篇关于URL连接codeD结肠400错误的请求解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆