- Techno Manor
- Существует ли предел объема данных в GET-запросе?
- HTTP GET with Request body – Guidelines
- What is the maximum size of Url in GET
- RFC Specification
- Specification and what it meant to us?
- GET support Body in .NET Core
- GET doesn’t support Body in .NET Framework
- SOAP UI – No support
- Using Swagger – No support
- Server Configuration issues
- Proxy Issues
- Summary
- References:
- Related Posts
Techno Manor
There is no thumb rule made for the maximum URL size of HTTP Get Request as per RFC 2616 (Hypertext Transfer Protocol — HTTP/1.1 – Section 3.2.1). Limits are imposed by various browsers and respective servers. These limits must be considered collectively while passing the query string passed in the URL in any of the HTTP Requests. If the URL size exceeds the URL Size limit imposed by the respective browser, the request will not be passed to the server & unnecessary effort will be required to debug & handle this situation.
To avoid this kind of a situation, one must account for this possibility in earlier stages of development. I have compiled the limits and other basic information regarding the HTTP Get Request
Browser | Maximum URL Size | Remarks |
Internet Explorer | 2048 B | Microsoft Internet Explorer has a maximum uniform resource locator (URL) length of 2,083 characters. Internet Explorer also has a maximum path length of 2,048 characters. This limit applies to both POST request and GET request URLs.If you are using the GET method, you are limited to a maximum of 2,048 characters, minus the number of characters in the actual path. |
Mozilla Firefox | >100 KB | The address bar doesn’t shows any characters beyond 65,536 characters. But the URL Size can be more than that, though you cannot view it in the address bar. This holds for FireFox 1.5 up until the current FireFox version |
Opera | >200 KB | The URL is completely visible in the address bar even at such a big range |
Chrome,Safari | >100 KB | Both browsers are webkit based and seems to have almost same limit as firefox |
Server | Maximum URL Size | Remarks |
Apache | >128 KB | The size is changed using the LimitRequestLine setting of the server |
IIS | >16 KB | Default value is 16 KB and maximum limit is 16 MB |
Lotus Notes | 4 KB | – |
Let’s understand the basic difference between a GET Request and a POST Request. GET requests are made to request a particular resource from the server. Whatever information is required to fetch the desired resource are passed as query string parameters. While POST Requests are made to post some data to a particular resource for processing as well as request a response. We should not use GET Requests to have data posted to the server, it should only be used, as its name suggests, to get a particular resource from the server. There is a thin but very clear line between logical usage of both
Very long URLs are not recommended at all. For a web based application to be cross browser compatible, the Get Method must not be used for passing very long strings, containing more than 2000 characters. If you are facing a situation where you need to use URLs to contain huge number of characters, then give it another thought
Существует ли предел объема данных в GET-запросе?
Насколько длинной может быть URL в обычной ссылке?
Такую ссылку планирую вставлять в письма из формы обратной связи, чтобы админ в один клик мог перейти на сайт и автоматом вставить присланный пользователем текст в форму ответа. Хранить в базе не вариант — она не резиновая.
Средний 2 комментария
2048 символов, все зависит от лимита сервера и браузера
Владимир Коротенко, ясно. Буду тогда пробовать вставлять POST-форму в письмо, вроде бы она более-менее поддерживается современными почтовыми сервисами.
Владимир Коротенко, Нет, не так. URL ограничен 2048 символами лишь в обозревателе интернета (Internet Explorer).
like-a-boss, то есть в теории в хеш можно запихнуть и больше? А потом просчитать javascript-ом после перехода.
Надим Закиров, да, но здесь от браузера напрямую зависит, по информации из интернета некоторые и 100.000 символов держат. Я лишь могу посоветовать провести опыт и сделать это для разных браузеров. Современные держат сильно больше 2k. А вообще используйте инструменты по назначению.
like-a-boss, собственно меня интересует только хром и хромоподобные. Похоже надо проводить натурный тест.
like-a-boss, Даже самые упоротые держат 64к
А если учесть национальные символы то 32к или даже 16К
Можно попробовать сжимать текст перед отправкой, например так:
https://www.google.com/url?sa=t&source=web&rct=j&u.
Провел натурные испытания. По итогам, действительно, если в теле GET-запроса передать больше 2048 символов, то сервер выдаёт ошибку — сам браузер вполне нормально воспринимает, а вот сервер уже нет. Попробовал передать текст в виде хеша в адресной строке, здесь ситуация намного лучше — удалось спокойно передать более 10 000 русских букв. Данного объема мне в принципе достаточно для реализация задумок, всем спасибо)
HTTP GET with Request body – Guidelines
If you are reading this article then I think you are looking at the possible use case of using HTTP GET with request body parameters.
Similar guidelines discussed here can be used as a reference for HTTP idempotent methods like DELETE methods also.
We will cover below a few aspects in the article,
- What is the maximum size of Url in GET
- RFC Specification
- Specification and what it meant to us?
- GET support Body in .NET Core
- GET doesn’t support Body in .NET Framework
- Using Fiddler – Warning for GET
- SOAP UI – No support
- PostMan UI- Support
- Using Swagger – No support
- Server Configuration issues
- Proxy Issues
- Summary
There could be multiple legitimate use cases for this you might be having already. But for me recently I needed to send very large input using the GET method and wanted to verify if I can send large input with body parameters.
What is the maximum size of Url in GET
We can not send very large inputs due to technical limitations of maximum URL length size which is found to be approximately ~2000 characters in general.
These limitations are more found on the server side and it is possible that some servers might just ignore the body of GET requests or behavior like caching GET requests might cause issues.
So in order to solve the issue, I looked at options like sending body parameters within the GET method.
I was stuck with this issue and I had to do a lot of analysis on finding the best resolutions.
I found that due to limitations on URI max length GET method can not be used for sending large input data either through putting details in URI directly or using the query parameter within the URL.
RFC Specification
As per RFC 7231 below are guidelines for rest get with the body,
GET is the primary mechanism of information retrieval and the focus of almost all performance optimizations.
A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.
Specification and what it meant to us?
Specification clarifies the support for the GET method with body parameters. But please note that it also warns us of its usage.
So if the length of parameters is longer and the server indeed receives the data from the body that supports it then you should be good to follow these specifications.
You must also validate other Test tools supporting it like Postman, Swagger, and Soap UI.
But, I wanted to see a more legitimate reason for not sending Body parameters in GET.
Below are a few major limitations and guidelines elaborating to use or not to use HTTP GET or DELETE method with body parameters.
Below are a few examples with some guidelines which can help you decide to opt IN/OUT of this support in your APIs.
GET support Body in .NET Core
After following the above specifications, I validated the .NET Core support for GET method with the Body parameter.
GET method was successful with [FromBody] parameters proving .NET Core has already added support in accordance with the specification.
Please see the below implementation,
[AllowAnonymous] [HttpGet] public IActionResult Token([FromBody]LoginModel login)Here is the Client-side code to execute the GET method with Body,
var request = new HttpRequestMessage < Method = HttpMethod.Get, RequestUri = new Uri("https://localhost:44341/api/auth"), Content = new StringContent(json, Encoding.UTF8, "application/json") >;
Please see here for a complete sample code for GET and DELETE requests.
GET doesn’t support Body in .NET Framework
GET doesn’t support Body in .NET Framework and gives the below error,
"Cannot send a content-body with this verb-type."
Fiddler warns you but allows us to send the body and the operation runs successfully.
SOAP UI – No support
I don’t find support exists for sending body parameters with GET method using SOAP UI.
The recent version has added support for sending body parameters with GET method using POSTMan UI.
Using Swagger – No support
Swagger Open API documentation gives the below error for GET method,
“Failed to execute ‘fetch’ on Windows. Request with GET/HEAD method can not have the body”.
Swagger gives the below error for DELETE method,
“DELETE operations cannot have a request Body”
Server Configuration issues
- A lot of servers cache the responses to GET and HEAD requests. This behavior might cause issues.
- It’s also possible that the Server might just ignore the body of GET request.
Proxy Issues
Please be cautious that proxies might break your request in various ways if the body is included in GET method.
A few other reasons alarming us to not use GET with Body are as below,
- Amazon CloudFront doesn’t support GET with the Body parameter.
- Sping-framework doesn’t support GET with the body.
- XMLHttpRequest doesn’t support GET with the body.
- Most Javascript libraries don’t support GET with a body.
Few examples where GET with the body is supported,
- Elastic search support GET with body parameters. (This is the only example, I found in the support.)
- Recent .NET Core framework-based application support GET with body
Other useful references:
Summary
Today in this article we looked at HTTP GET support for body parameters. Although the specification clarifies support for GET method with body parameters, it also warns us about its usage and clarifies that it is not useful to do so. We looked at multiple aspects of using GET with body parameters including Tools and Testing support with its pros and cons etc.
Do you have any comments or ideas or any better suggestions to share?
Please sound off your comments below.
Happy Coding !!
References:
Related Posts
Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published best practices and guidelines for software design and development.