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
When the last 10+ characters it gives me a bad request. Any help greatly appreciated.
The HyperText Transfer Protocol (HTTP) 400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error (for example, malformed request syntax, invalid request message framing, or deceptive request routing).
The 400 (Bad Request) status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). A business rule doesn't fall under any of those three examples.
Just documenting my experience:
My issue was the one pointed by @Mark at the question comments:
"by default the maximum url segment length is 260"
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:
"Replaced the url segment into a querystring parameter and it worked fine"
In summary, instead of doing:
http://path.to.website/very-long-string-goes-here/
I just did:
http://path.to.website/?key=very-long-string-goes-here
run in powershell
Set-ItemProperty -Path HKLM:\System\CurrentControlSet\Services\HTTP\Parameters -Name UrlSegmentMaxLength -Value 2000 -Type "Dword"
then do net stop http
and net start http
.
https://blogs.msdn.microsoft.com/amyd/2014/02/06/response-400-bad-request-on-long-url/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With