HTTP
请求和响应
请求的代码分为请求行,请求头和请求体三部分.其中GET获取操作没有请求体
响应的代码分为状态行,响应头和响应体三部分
可以利用curl和chorme发送和设置请求,利用node.js来设置响应
用curl或者Chrome发送请求
用curl代理请求为例
λ curl -v -X POST --data 'hello' http://deibo:8080/x // 发送了POST请求
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying 127.0.0.1:8080... // 获取IP
* Connected to deibo (127.0.0.1) port 8080 (#0)
> POST /x HTTP/1.1 // 请求行
> Host: deibo:8080 // 域名 ______
> User-Agent: curl/7.79.1 // 用户代理curl 请
> Accept: */* // 要求回复文件格式 求
> Content-Length: 5 // 头
> Content-Type: application/x-www-form-urlencoded ______
>
* Mark bundle as not supporting multiuse // 请求体
< HTTP/1.1 200 OK // 状态行
< Content-Type: text/css;charset=utf-8 // 文件类型和字符集 ___
< Date: Thu, 19 May 2022 01:20:14 GMT 响
< Connection: keep-alive 应
< Keep-Alive: timeout=5 头
< Transfer-Encoding: chunked ___
<body{color: red;}* Connection #0 to host deibo left intact // 响应体