OData URL Length Limits

Browsers have a limit on the length of URLs. IE has a limitation that Url must not exceed 2K characters.

When I form a query equal to $ filter, I can compare with several input values. In this case, the length of Url will exceed 2K.

Does OData indicate any restrictions on the length of the URL?

thanks

+7
odata
source share
3 answers

OData itself does not limit the length of the URL, but as you have noticed, most clients and servers do this. Therefore, it is usually useful not to create the URL for too long.

The problem you are talking about (implementation of the Contains operator or something similar) has two possible workarounds:

1) Use a service operation to process such a request. You can pass multiple input values ​​encoded as a string or something like that, or maybe the service operation still knows about it.

2) Use the long $ filter, but send the request in a $ batch request. The advantage is that the limit on Url is much larger, and you are unlikely to hit it. The disadvantage is that even if you try to execute a GET request, because of $ batch it moves as a POST request over the Internet and therefore it will not be cached.

+6
source share

I put off @Vitek's answer to the OP question:

OData itself does not limit the length of url

But if others who come here due to IIS restrictions : The request filtering module is configured to deny a request where the query string is too long. they can use my answer. Follow these error instructions:

Verify the configuration/system.webServer/security/requestFiltering/requestLimits@maxQueryString setting in the applicationhost.config or web.config file.

Follow the instructions:

 <configuration> <system.webServer> <security> <requestFiltering> <requestLimits maxQueryString="50000"> </requestLimits> ... 

You may also get this error: The length of the query string for this request exceeds the configured maxQueryStringLength value.

This method is described here and here , and it looks like this

 <configuration> <system.web> <httpRuntime maxQueryStringLength = "50000" ... /> 
+1
source share

I did not find how $batch . so I used $filter to send a long request. Its pretty easy:

 DataServiceQuery<CLIENT> ordersQuery = DataServiceQuery<CLIENT>)this.context.CLIENTS.AddQueryOption("$filter", MyFilter()); 

where MyFilter() returns the following string: "ID_CLIENT = 1 or ID_CLIENT = 2"

Note. Do not use the uppercase letter I. This leads to errors. use and not and

0
source share

All Articles