我收到一个400错误的请求-请求长度超过320个以上字符时,Url无效 [英] I get a 400 bad request - invalid Url when the length of the request exceeds 320+ characters
问题描述
不确定是什么原因.还在Web.config中添加了以下内容.maxUrlLength ="1024" maxQueryStringLength ="1024" requestPathInvalidCharacters =" maxRequestLength ="1024" RelaxUrlToFileSystemMapping ="true"我对uri参数进行了编码并发送了请求,但始终收到无效的url.地址: HTTP://本地主机:51840/API/XXXXXXX/XXXXXXXXXXXX/n4cEF3OM0LC0q8I6OMe0XdHo8evXnoeyC06A%252fL%252fu0a%252f6e0RQrdxl2%252fPkSKNfh4aEQm78TReX1zIfGDB1bgH%252bGBEI%252fBw6i0DwQ6%252b3dk6yjs1UZqqICQye6QqVX8bJT%252fBK7GE8a22FeXJiPVtEgFRmp4WcHc4pIRHaE6QGK28kiASGFfUC9tDdRZhLfmYJsluGpsseSUOc5Inxlf3fTFNe7sg7gixrLTlwhfJIATZWWsPc%252bfo6BITTFA%253D 253D%
Not sure what could be the reason. Added the following in Web.config also. maxUrlLength="1024" maxQueryStringLength="1024" requestPathInvalidCharacters="" maxRequestLength="1024" relaxedUrlToFileSystemMapping="true" I encode the uri parameter and send the request but get a invalid url all the time. Url: http://localhost:51840/api/xxxxxxx/xxxxxxxxxxxx/n4cEF3OM0LC0q8I6OMe0XdHo8evXnoeyC06A%252fL%252fu0a%252f6e0RQrdxl2%252fPkSKNfh4aEQm78TReX1zIfGDB1bgH%252bGBEI%252fBw6i0DwQ6%252b3dk6yjs1UZqqICQye6QqVX8bJT%252fBK7GE8a22FeXJiPVtEgFRmp4WcHc4pIRHaE6QGK28kiASGFfUC9tDdRZhLfmYJsluGpsseSUOc5Inxlf3fTFNe7sg7gixrLTlwhfJIATZWWsPc%252bfo6BITTFA%253d%253d
If I reduce the url to the following it works fine. http://localhost:51840/api/xxxxxxx/xxxxxxxxxxxx/n4cEF3OM0LC0q8I6OMe0XdHo8evXnoeyC06A%252fL%252fu0a%252f6e0RQrdxl2%252fPkSKNfh4aEQm78TReX1zIfGDB1bgH%252bGBEI%252fBw6i0DwQ6%252b3dk6yjs1UZqqICQye6QqVX8bJT%252fBK7GE8a22FeXJiPVtEgFRmp4WcHc4pIRHaE6QGK28kiASGFfUC9tDdRZhLfmYJsluGpsseSUOc5Inxlf3fTFNe7sg7gixrLTlwhfJIATZWWsPc%252bfo6BI
当最后10个字符以上时,我提出了一个错误的要求.任何帮助都将不胜感激.
When the last 10+ characters it gives me a bad request. Any help greatly appreciated.
推荐答案
只需记录一下我的经历即可:
Just documenting my experience:
我的问题是@Mark在问题评论中指出的问题:
My issue was the one pointed by @Mark at the question comments:
"默认情况下,最大网址段长度为260 "
他建议在注册表中增加此限制,但我不希望出现这种麻烦.@Vignesh T的建议效果更好:
He suggested to increase this limit in the registry, but I didn't want this kind of trouble. The suggestion by @Vignesh T worked better:
"将url段替换为querystring参数,效果很好"
总而言之,不要这样做:
In summary, instead of doing:
http://path.to.website/very-long-string-goes-here/
我刚刚做过:
http://path.to.website/?key=very-long-string-goes-here
这篇关于我收到一个400错误的请求-请求长度超过320个以上字符时,Url无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!