请求一个网页
命令行敲入$ curl -v -I hdcjh.xyz
意思是仅显示请求头和响应头
request
HEAD / HTTP/1.1
Host: hdcjh.xyz
User-Agent: curl/7.58.0
Accept: */*
response
HTTP/1.1 200 OK
Server: nginx/1.10.3 (Ubuntu)
Date: Fri, 11 Oct 2019 09:01:39 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 12507
Connection: keep-alive
Expires: Fri, 11 Oct 2019 09:16:55 GMT
Cache-Control: max-age=1200
X-Frame-Options: SAMEORIGIN
Vary: Cookie
Set-Cookie: sessionid=0rnlqrgp0whc9m40wlvegafnpdez535m; expires=Fri, 25 Oct 2019 09:01:39 GMT; HttpOnly; Max-Age=1209600; Path=/; SameSite=Lax
Request分为以下几个部分:
结构部分 | 具体的值 |
---|---|
请求方法 | HEAD |
URI | / |
协议版本 | HTTP/1.1 |
分割符(换行符) | \r\n |
HTTP头部 | key-name : key-value |
… | … |
分割符(换行符) | \r\n\r\n |
HTTP报体 | 上面没有显示,但是报体i可以是任意数据类型 |
注意: 连续两个 \r\n
代表报头结束, 进入报体部分
Response 分为以下几个部分:
结构部分 | 具体的值 |
---|---|
协议版本 | HTTP/1.1 |
状态码 | 200 |
状态描述 | OK |
分割符(换行符) | \r\n |
HTTP头部 | key-name : key-value |
… | … |
分割符(换行符) | \r\n\r\n |
HTTP报体 | 上面没有显示,但是报体i可以是任意数据类型 |
GET查询
浏览器地址输入http://localhost:2019/query/example;?author=cjh&&category=C++
服务器得到:
GET /query/example;?author=cjh&&category=C++ HTTP/1.1
Host: localhost:2019
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
Sec-Fetch-Site: none
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
我用的是Chrome, 当服务器未返回任何数据的时候, Chrome 会连续尝试 3 次
POST查询
前端简单写个表单
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div>
<form action="http://localhost:2019/example_form" method="POST">
<input type="text" id="author">
<input type="text" id="category">
<input type="submit">
</form>
</div>
</body>
</html>
HTTP 头里没有字段信息
POST /example_form HTTP/1.1
Host: localhost:2019
Connection: keep-alive
Content-Length: 0
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: null
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
Sec-Fetch-Site: cross-site
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9