Home php教程 php手册 HTTP中GET长度问题

HTTP中GET长度问题

Jun 06, 2016 pm 08:13 PM
get http interface length question

曾做过一个plist的接口,需要将参数编码后放在URL上传递,编码后的URL很长,长到让人担心这么传有没有问题?要弄清这个问题得先弄明白HTTP报文请求格式,借用网上一张图片: 一个HTTP请求由四部分组成:Request Line、Headers、空行和Request Body。见下面GE

曾做过一个plist的接口,需要将参数编码后放在URL上传递,编码后的URL很长,长到让人担心这么传有没有问题?要弄清这个问题得先弄明白HTTP报文请求格式,借用网上一张图片:

http

一个HTTP请求由四部分组成:Request Line、Headers、空行和Request Body。见下面GET示例:

http_get

可以看到GET请求时,数据放在Request Line中Request-URI传递;若发送POST请求时,数据则放在Request Body中传递,不同的地方决定了其享受不同的待遇。

HTTP手册上是这么说的:

HTTP协议不会对URI做任何限制,服务端必须能处理不限长度的URI,如果不能处理则返回414

The HTTP protocol does not place any a priori limit on the length of a URI. Servers MUST be able to handle the URI of any resource they serve, and SHOULD be able to handle URIs of unbounded length if they provide GET-based forms that could generate such URIs. A server SHOULD return 414 (Request-URI Too Long) status if a URI is longer than the server can handle (see section 10.4.15).

http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.2.1

虽然HTTP协议中并未限制Request-URI的大小,但不同浏览器和WEB服务器则有不同的限制。

浏览器限制

不同的浏览器限制不同,若通过浏览器访问,2000个字符长度以内基本上都可以兼容。

WEB服务器

这里在SAE上写了个脚本,访问地址http://ipbt.vipsinaapp.com/demo/Http/request.php?len=8151,看到可以正常访问,若len参数改为8152则提示

414 Request-URI Too Large

可见这是当前NGINX环境下的极限值,此时Request Line的总长度为8190。同样的请求本地Apache配置的服务器,当Request Line长度超过8190时,Aapche也会提示

Request-URI Too Large

The requested URL's length exceeds the capacity limit for this server.

可见Nginx和Apache在请求行的长度控制上是一致的,默认都是8190个字符长度。但同时该值也是可以调整的,Nginx中可以通过large_client_header_buffers来控制请求行的最大长度;Apache中可设置LimitRequestLine的值来控制。

LimitRequestLine指令
语法:LimitRequestLine bytes
默认:LimitRequestLine 8190
这个指令用来设置客户端发送的HTTP请求行的最大字节数。请求行包括HTTP方法、URL、协议版本等。因此LimitRequestLine指令能够限制URL的长度,服务器会需要这个值足够大以装载它所有的资源名,包括可能在GET请求中所传递的查询部分的所有信息。
一般情况下,不要更改这个值,使用默认即可。

当把本地Apache LimitRequestLine 调整为 8190000后,加3个0在请求也没问题。。。

GET /ipbt/1/demo/Http/response.php?s=11111111.....
Host: localhost:80
Connection: Close
HTTP/1.1 200 OK
Date: Tue, 05 Aug 2014 23:19:17 GMT
Server: Apache/2.2.11 (Win32) PHP/5.4.7
X-Powered-By: PHP/5.4.7
Content-Length: 14
Connection: close
Content-Type: text/html
Length:8000000
Copy after login

可见GET请求实际上也是没有长度限制的,只是浏览器和WEB服务器做了控制。。。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the internal interfaces of a computer motherboard? Recommended introduction to the internal interfaces of a computer motherboard What are the internal interfaces of a computer motherboard? Recommended introduction to the internal interfaces of a computer motherboard Mar 12, 2024 pm 04:34 PM

When we assemble the computer, although the installation process is simple, we often encounter problems in the wiring. Often, users mistakenly plug the power supply line of the CPU radiator into the SYS_FAN. Although the fan can rotate, it may not work when the computer is turned on. There will be an F1 error "CPUFanError", which also causes the CPU cooler to be unable to adjust the speed intelligently. Let's share the common knowledge about the CPU_FAN, SYS_FAN, CHA_FAN, and CPU_OPT interfaces on the computer motherboard. Popular science on the CPU_FAN, SYS_FAN, CHA_FAN, and CPU_OPT interfaces on the computer motherboard 1. CPU_FANCPU_FAN is a dedicated interface for the CPU radiator and works at 12V

Common programming paradigms and design patterns in Go language Common programming paradigms and design patterns in Go language Mar 04, 2024 pm 06:06 PM

As a modern and efficient programming language, Go language has rich programming paradigms and design patterns that can help developers write high-quality, maintainable code. This article will introduce common programming paradigms and design patterns in the Go language and provide specific code examples. 1. Object-oriented programming In the Go language, you can use structures and methods to implement object-oriented programming. By defining a structure and binding methods to the structure, the object-oriented features of data encapsulation and behavior binding can be achieved. packagemaini

Introduction to PHP interfaces and how to define them Introduction to PHP interfaces and how to define them Mar 23, 2024 am 09:00 AM

Introduction to PHP interface and how it is defined. PHP is an open source scripting language widely used in Web development. It is flexible, simple, and powerful. In PHP, an interface is a tool that defines common methods between multiple classes, achieving polymorphism and making code more flexible and reusable. This article will introduce the concept of PHP interfaces and how to define them, and provide specific code examples to demonstrate their usage. 1. PHP interface concept Interface plays an important role in object-oriented programming, defining the class application

How to implement HTTP streaming using C++? How to implement HTTP streaming using C++? May 31, 2024 am 11:06 AM

How to implement HTTP streaming in C++? Create an SSL stream socket using Boost.Asio and the asiohttps client library. Connect to the server and send an HTTP request. Receive HTTP response headers and print them. Receives the HTTP response body and prints it.

What is the PHP array length limit? What is the PHP array length limit? Mar 13, 2024 pm 06:30 PM

There is no fixed limit to the length of an array in PHP, it can be dynamically adjusted according to the system's memory size. In PHP, an array is a very flexible data structure that can store any number of elements, and each element can be a value of any type, or even another array. The length limit of PHP arrays mainly depends on the memory size of the system and the memory limit of PHP configuration. Generally speaking, if the system's memory is large enough and PHP's memory limit is high enough, the length of the array can be very large. However, if your system is low on memory or

Application of interfaces and abstract classes in design patterns in Java Application of interfaces and abstract classes in design patterns in Java May 01, 2024 pm 06:33 PM

Interfaces and abstract classes are used in design patterns for decoupling and extensibility. Interfaces define method signatures, abstract classes provide partial implementation, and subclasses must implement unimplemented methods. In the strategy pattern, the interface is used to define the algorithm, and the abstract class or concrete class provides the implementation, allowing dynamic switching of algorithms. In the observer pattern, interfaces are used to define observer behavior, and abstract or concrete classes are used to subscribe and publish notifications. In the adapter pattern, interfaces are used to adapt existing classes. Abstract classes or concrete classes can implement compatible interfaces, allowing interaction with original code.

Insight into Hongmeng system: actual function measurement and usage experience Insight into Hongmeng system: actual function measurement and usage experience Mar 23, 2024 am 10:45 AM

As a new operating system launched by Huawei, Hongmeng system has caused quite a stir in the industry. As a new attempt by Huawei after the US ban, Hongmeng system has high hopes and expectations. Recently, I was fortunate enough to get a Huawei mobile phone equipped with Hongmeng system. After a period of use and actual testing, I will share some functional testing and usage experience of Hongmeng system. First, let’s take a look at the interface and functions of Hongmeng system. The Hongmeng system adopts Huawei's own design style as a whole, which is simple, clear and smooth in operation. On the desktop, various

Example of Curl Get command Example of Curl Get command Mar 20, 2024 pm 06:56 PM

In Linux, URL or Curl client is a popular command line utility that allows you to transfer data over the network using various protocols such as HTTPS, HTTP, FTP, etc. It allows you to send and receive data using its get, post and request methods. Among them, you need to use the "get" method frequently. Therefore, it becomes crucial to learn various methods and various options that you can use to increase your productivity. "Performing a curl operation is as simple as entering a few simple commands. Although it seems simple, many users do not fully realize its potential. Therefore, this short guide provides some information on how to perform curl operations on Linux systems. Example using the "curlget" command." Curl

See all articles