匿名
未登录
创建账号
登录
运维百科
搜索
查看“http/数据组成”的源代码
来自运维百科
命名空间
页面
讨论
更多
更多
页面操作
阅读
查看源代码
历史
刷新
←
http/数据组成
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
HTTP请求的数据组成可分为以下部分,按顺序排列: == 请求行(Request Line) == 格式:<方法> <请求目标> <HTTP版本> 方法:GET/POST/PUT/DELETE等 请求目标:通常为URI路径(绝对路径或完整URL) HTTP版本:HTTP/1.1或HTTP/2 == 请求头(Request Headers) == 通用头:Date/Cache-Control/Connection等 请求头:Host/User-Agent/Accept/Authorization等 实体头:Content-Type/Content-Length(当有请求体时) 每个头字段占一行,格式:<字段名>: <值> == 空行 == 必须的CRLF(\r\n)分隔符,标识请求头结束 == 请求体(Request Body) == 可选内容,GET/HEAD等方法通常没有 常见数据格式: application/x-www-form-urlencoded multipart/form-data application/json text/xml 需要配合Content-Type和Content-Length头 == 其他特性: == 块传输编码(Transfer-Encoding: chunked) 持久连接(Connection: keep-alive) 内容协商(Accept-*系列头) Cookie处理(Cookie头) 注:HTTP/2协议使用二进制帧封装,但逻辑结构保持相同。HTTPS会在传输层加密整个HTTP报文。 == 例子 == === 1. GET 请求(不带请求体) === <pre> GET /api/users?id=123 HTTP/1.1 Host: example.com User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) Accept: application/json Accept-Language: en-US,en;q=0.9 Connection: keep-alive Authorization: Bearer abc123xyz Cookie: session_id=abcde12345 </pre> === 2. POST 请求(带 JSON 请求体) === <pre> POST /api/login HTTP/1.1 Host: example.com Content-Type: application/json Content-Length: 56 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) Accept: */* Authorization: Basic dXNlcjpwYXNz {"username": "admin", "password": "secret123"} </pre> === 3. POST 请求(带表单数据) === <pre> POST /submit-form HTTP/1.1 Host: example.com Content-Type: application/x-www-form-urlencoded Content-Length: 27 Referer: https://example.com/form username=admin&password=123456 </pre> === 4. POST 请求(文件上传,multipart/form-data) === <pre> POST /upload HTTP/1.1 Host: example.com Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryABC123 Content-Length: 342 ------WebKitFormBoundaryABC123 Content-Disposition: form-data; name="username" admin ------WebKitFormBoundaryABC123 Content-Disposition: form-data; name="avatar"; filename="photo.jpg" Content-Type: image/jpeg <binary file data here> ------WebKitFormBoundaryABC123-- </pre> [[http/post/multipart/form-data/boundary|boundary]]
返回
http/数据组成
。
导航
导航
首页
FAQ
随机页面
wiki工具
wiki工具
特殊页面
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志