简体   繁体   中英

webapi odata - long url causes “HTTP Error 400. The request URL is invalid”

We have a project with a selfhosted odata/webapi. When recieving requests with long strings we get the following error:

"HTTP Error 400. The request URL is invalid"

Is it possible to configure webapi to accept longer parameters?

An example url:

GET
/api/bookings/Service.GetSegments(ids='189,196,280,301,316,329,491,511,464,528,530,527,542,372,283,259,231,56,84,98,114,135,175,154,161,85,203,206,217,284,343,344,357,419,425,112,586,432,441,448,455,462,465,358,371,385,392,399,405,413,581,526,538,531,476,490,336,508,525,499,315,260,263,281,224,238,245,246,99,57,58,77,168,180,147,126,133',start='2018-01-20T23:00:00.000Z',end='2018-01-27T23:00:00.000Z') 

A shorter url like this will work fine:

GET
/api/bookings/Service.GetSegments(ids='189,196,280,301,316,329,491',start='2018-01-20T23:00:00.000Z',end='2018-01-27T23:00:00.000Z') 

This is the method in the controller:

 public IHttpActionResult GetSegments(ODataQueryOptions<Segments> odataQueryOption,
        string ids, string start, string end)
    {
       ...

If you replace the url segment into a querystring it will work fine.

By default, url segments have maximum length of 260.

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