【发布时间】:2012-11-26 19:44:30
【问题描述】:
我的路线如下:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}/{uri}",
defaults: new { id = RouteParameter.Optional, uri = RouterParameter.Optional }
);
我有一个 Base64 编码的 uri 来代替 {uri} 参数。它没有非法字符(我已正确格式化并检查以确保)。但是,它的长度约为 300-400 个字符。
当我使用 long base64 参数向该地址发送 DELETE 请求时,我收到 400 BAD STATUS, INVALID URL 响应。缩短参数时,它起作用。我怀疑存在最大路径问题?
使用查询字符串代替路径参数是可行的,但我宁愿继续使用 RESTful 方法。我可以在我的 Web API 项目上更改配置设置以允许更长的基于路径的参数吗?
这行得通:
http://localhost:99999/api/reg/10?uri=<long_base64_parameter>
这不起作用:
http://localhost:99999/api/reg/10/<long_base64_parameter>
【问题讨论】:
-
你是如何正确格式化的?
-
你使用了encodeURIComponent吗? developer.mozilla.org/en-US/docs/JavaScript/Reference/…
-
@JayC 是的,非法字符被替换了。我检查了传出的 HttpRequest 并确认参数中只有字母数字字符。请注意,我的请求在使用查询字符串时有效,但在使用 RESTful 路径参数时无效。
标签: http rest asp.net-mvc-4 asp.net-web-api