简体   繁体   中英

URL limits in http.sys for query parameters in GET requests

While http.sys has limit on UrlSegmentMaxLength which is 260 by default, I couldn't find if it applies on URL query parameters part. For instance, when I host a WCF service as WebServiceHost w/o IIS, each request that is having a segment longer then 260 chars fails with 400 error. So, my first impression was it must be applicable for query parameters as well. However, after couple experiments I figured that it doesn't impact on it. Tests successfully passed with parameters a way longer than default maximum. So, I'm wondering if the UrlSegmentMaxLength impacts on query part? So if it doesn't, what parameter (if any) responsible for that and what those limitations are?

In other words, why the following request causes 400 Bad Request because of exceeding the number of chars allowed in Windows settings:

HTTP GET http://my.com/foo/very-long-segment-5k-chars?arg=1

but this one works fine:

HTTP GET http://my.com/foo?arg=very-long-argument-5k-chars

There are usually two reasons for 400 Bad Request in WCF. 400 Bad Request will appear if the requested http verb is wrong, and 400 Bad Request will appear if the request format is wrong. According to your description, this may be caused by the incorrect format of the URL, you can try to enable the help document to view the correct request path.

在此处输入图片说明

This is the URL we want to request the service, we must make sure to send the request in accordance with this URL format, otherwise 400 Bad Request will appear.

To enable the help document, we need to add the following configuration to the configuration file:

<endpointBehaviors>  
   <behavior name="RESTEndpointBehavior">  
      <webHttp enableHelp="true"/>  
   </behavior>  
</endpointBehaviors>  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM