Golang基础知识Go语言java基础与进阶

Web的工作方式

2018-07-02  本文已影响102人  仕明同学
用户访问一个Web站点的过程

需要注意的是:客户端和服务器之间的通信是非持久连接的,也就是当服务器发送了应答后就与客户端断开连接了,等待下一次请求。

URL和DNS解析

scheme://host[:port#]/path/.../[?query-string][#anchor]
scheme         指定底层使用的协议(例如:http, https, ftp)
host           HTTP服务器的IP地址或者域名
port#          HTTP服务器的默认端口是80,这种情况下端口号可以省略。如果使用了别的端口,必须指明,例如 http://www.cnblogs.com:8080/
path           访问资源的路径
query-string   发送给http服务器的数据
anchor         锚
DNS工作原理

HTTP协议详解

HTTP请求包(浏览器信息)

GET /domains/example/ HTTP/1.1      //请求行: 请求方法 请求URI HTTP协议/协议版本
Host:www.iana.org               //服务端的主机名
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4          //浏览器信息
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8  //客户端能接收的MIME
Accept-Encoding:gzip,deflate,sdch       //是否支持流压缩
Accept-Charset:UTF-8,*;q=0.5        //客户端字符编码集
//空行,用于分割请求头和消息体
//消息体,请求资源参数,例如POST传递的参数

Request URL:https://www.jianshu.com/
Request Method:GET
Status Code:304 Not Modified
Remote Address:127.0.0.1:8888
Response Headers
view source
Cache-Control:max-age=0, private, must-revalidate
Connection:keep-alive
Content-Security-Policy:script-src 'self' 'unsafe-inline' 'unsafe-eval' *.jianshu.com *.jianshu.io api.geetest.com static.geetest.com dn-staticdown.qbox.me zz.bdstatic.com *.google-analytics.com hm.baidu.com push.zhanzhang.baidu.com res.wx.qq.com qzonestyle.gtimg.cn as.alipayobjects.com ;style-src 'self' 'unsafe-inline' *.jianshu.com *.jianshu.io api.geetest.com static.geetest.com ;
Date:Mon, 02 Jul 2018 09:10:04 GMT
ETag:W/"e5bf3f5c57dcac3addf979d6e74fa906"
Server:Tengine
Set-Cookie:locale=zh-CN; path=/
Strict-Transport-Security:max-age=31536000; includeSubDomains; preload
X-Content-Type-Options:nosniff
X-Dscp-Value:0
X-Frame-Options:DENY
X-Request-Id:01a51f5d-b6ea-45c2-91a7-5fdec3a8eb70
X-Runtime:0.022833
X-Via:1.1 PSfjfzdx2mj93:9 (Cdn Cache Server V2.0), 1.1 yangdianxin66:10 (Cdn Cache Server V2.0)
X-XSS-Protection:1; mode=block
Request Headers
view source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:zh-CN,zh;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:__guid=163745081.662820947905634200.1526461023901.8958; signin_redirect=https%3A%2F%2Fwww.jianshu.com%2F; read_mode=day; default_font=font2; monitor_count=5; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22163682ac930acd-0e49b894cda713-6b1b1279-2073600-163682ac9319a0%22%2C%22%24device_id%22%3A%22163682ac930acd-0e49b894cda713-6b1b1279-2073600-163682ac9319a0%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22%22%2C%22%24latest_referrer_host%22%3A%22%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%7D%7D; Hm_lvt_0c0e9d9b1e7d617b3e6842e85b9fb068=1528795394,1530514591; Hm_lpvt_0c0e9d9b1e7d617b3e6842e85b9fb068=1530522699; locale=zh-CN
Host:www.jianshu.com
If-None-Match:W/"e5bf3f5c57dcac3addf979d6e74fa906"
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36

由于简书地址是https,我通过fiddler去抓一个不是http的,看起来比较好看

get请求 post请求

HTTP响应包(服务器信息)

HTTP/1.1 200 OK                     //状态行
Server: nginx/1.0.8                 //服务器使用的WEB软件名及版本
Date:Date: Tue, 30 Oct 2012 04:14:25 GMT        //发送时间
Content-Type: text/html             //服务器发送信息的类型
Transfer-Encoding: chunked          //表示发送HTTP包是分段发的
Connection: keep-alive              //保持连接状态
Content-Length: 90                  //主体内容长度
//空行 用来分割消息头和主体
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... //消息体
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 02 Jul 2018 09:21:33 GMT
Content-Type: text/html
Content-Length: 576063
Connection: keep-alive
Last-Modified: Mon, 02 Jul 2018 09:20:01 GMT
Vary: Accept-Encoding
X-Powered-By: shci_v1.03
Expires: Mon, 02 Jul 2018 09:22:28 GMT
Cache-Control: max-age=60
Age: 4
Via: http/1.1 ctc.ningbo.ha2ts4.97 (ApacheTrafficServer/6.2.1 [cHs f ]), http/1.1 ctc.xiamen.ha2ts4.41 (ApacheTrafficServer/6.2.1 [cHs f ])
X-Via-Edge: 153052329372561c48b773cd64cde73000845
X-Cache: HIT.41
X-Via-CDN: f=edge,s=ctc.xiamen.ha2ts4.34.nb.sinaedge.com,c=119.139.196.97;f=Edge,s=ctc.xiamen.ha2ts4.41,c=222.76.214.34

<!DOCTYPE html>
<!-- [ published at 2018-07-02 17:20:00 ] -->
<html>
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>新浪首页</title>
    <meta name="keywords" content="新浪,新浪网,SINA,sina,sina.com.cn,新浪首页,门户,资讯" />
    <meta name="description" content="新浪网为全球用户24小时提供全面及时的中文资讯,内容覆盖国内外突发新闻事件、体坛赛事、娱乐时尚、产业资讯、实用信息等,设有新闻、体育、娱乐、财经、科技、房产、汽车等30多个内容频道,同时开设博客、视频、论坛等自由互动交流空间。" />
    <link rel="mask-icon" sizes="any" href="//www.sina.com.cn/favicon.svg" color="red">
    <meta name="stencil" content="PGLS000022" />
...

HTTP协议是无状态的和Connection: keep-alive的区别

一次请求的request和response
上一篇 下一篇

猜你喜欢

热点阅读