美文网首页
[HTTP] 协议底层文本格式

[HTTP] 协议底层文本格式

作者: 爱上落入尘世间的你 | 来源:发表于2019-07-27 18:59 被阅读0次

平时使用http都是直接使用各种库区发起和接收http请求, 对于http底层格式的探究不多, 这次详细了解了一些http这个文本格式协议的运行流程

1. client.request.get

GET / HTTP/1.1
Accept: application/json
Host: localhost:9000
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.6 (Java/1.8.0_202-release)
Accept-Encoding: gzip,deflate

or

GET /?id=99 HTTP/1.1
Accept: application/json
Host: localhost:9000
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.6 (Java/1.8.0_202-release)
Accept-Encoding: gzip,deflate

2. client.request.post(normal)

POST / HTTP/1.1
Content-Type: application/json
Content-Length: 2
Host: localhost:9000
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.6 (Java/1.8.0_202-release)
Accept-Encoding: gzip,deflate

{}

3. client.request.post(x-www-form-urlencoded)

POST / HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 25
Host: localhost:9000
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.6 (Java/1.8.0_202-release)
Accept-Encoding: gzip,deflate

id=99&content=new-element

4. client.request.post(multipart/form-data)

POST / HTTP/1.1
Content-Length: 555
Content-Type: multipart/form-data; boundary=trJB5E5VXSMIf6OyGa7vnSQl2X-81n3
Host: localhost:9000
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.6 (Java/1.8.0_202-release)
Accept-Encoding: gzip,deflate

--trJB5E5VXSMIf6OyGa7vnSQl2X-81n3
Content-Disposition: form-data; name=".gitignore"; filename=".gitignore"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary

.idea/
node_modules/
package-lock.json


--trJB5E5VXSMIf6OyGa7vnSQl2X-81n3
Content-Disposition: form-data; name="README.md"; filename="README.md"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary

# simple-nodejs-proxy
a simple forward proxy implemented in node.js, and docker image is provided !

--trJB5E5VXSMIf6OyGa7vnSQl2X-81n3--

5. server.response(not chunked)

HTTP/1.1 200 OK
content-length: 11

hello world

6. server.response(chunked)

HTTP/1.1 200 OK
Transfer-Encoding: chunked

b
01234567890
5
12345
0

server的代码(node.js)

const net = require('net')

net.createServer(function (sock) {
    sock.on('data', function (data) {
        console.log(data.toString())
        sock.write('HTTP/1.1 200 OK\r\n');
        sock.write('Transfer-Encoding: chunked\r\n');
        sock.write('\r\n');

        sock.write('b\r\n');
        sock.write('01234567890\r\n');

        sock.write('5\r\n');
        sock.write('12345\r\n');

        sock.write('0\r\n');
        sock.write('\r\n');
    })
    sock.on('error', function(err)
    {
        console.log(err)
    })
}).listen(9000, '0.0.0.0')

相关文章

  • [HTTP] 协议底层文本格式

    平时使用http都是直接使用各种库区发起和接收http请求, 对于http底层格式的探究不多, 这次详细了解了一些...

  • 入门:HTTP(二)

    一、HTTP协议HTTP协议的底层其实是TCP协议和IP协议构建的 TCP(Transmission Contro...

  • 2018-12-15\网络与IP&node js服务器

    HTTP与TCP 协议 HTTP 协议的底层其实是由 TCP 协议和 IP 协议(简称 TCP/IP)构建的。关于...

  • NSURLSession学习笔记

    �Http协议-超文本传输协议 Http协议是应用层协议,底层要求的传输协议必须是可靠的传输协议,通常是TCP协议...

  • Objective-C的网络请求相关——Http超文本传输协议学

    �Http协议 - 超文本传输协议 Http协议是应用层协议,底层要求的传输协议必须是可靠的传输协议,通常是TCP...

  • HTTP系列 -- 网络 与 IP

    概述 HTTP协议的底层是由 TCP 协议和 IP 协议(简称TCP/IP)构建的。HTTP只规定了请求格式和相应...

  • HTTP2 协议前瞻

    HTTP/2 优势 HTTP/2 采用二进制格式传输数据,而非 HTTP/1.x 的文本格式。二进制格式在协议的解...

  • 网络知识笔记

    HTTP协议的底层其实是由TCP协议和IP协议构建的。 TCP传输控制协议(Transmission Contro...

  • 网络,IP,端口,路由

    HTTP协议的底层是有TCP协议和IP协议简称(TCP/IP)构建的。 TCP(Transmission Cont...

  • Android网络请求 v1.1

    Http协议库 HttpUrlConnetion同步处理网络请求底层支持Http1.0,Http1.1。缺点:An...

网友评论

      本文标题:[HTTP] 协议底层文本格式

      本文链接:https://www.haomeiwen.com/subject/ouaerctx.html