霍格沃兹测试学院 第九期_接口测试协议与代理_20190710

思寒_seveniruby for 霍格沃兹测试学院外部交流圈 · July 10, 2019 · Last by tom replied at August 28, 2019 · 1088 hits

接口协议

tcpdump

三次握手

数据传输http

四次挥手

Chrome DevTool

通过curl命令发起接口请求

curl 'https://stock.xueqiu.com/v5/stock/batch/quote.json?symbol=SOGO' -H 'Accept: */*' -H 'Referer: https://xueqiu.com/k?q=sogo' -H 'Origin: https://xueqiu.com' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'   -H 'Cookie: _ga=GA1.2.97938473.1556791189; device_id=c15c898fa623317fdaa696b5b25ea4e6; s=by11ypznnb; bid=18a1bec4795f9c5967fd96c6a12e9fb0_jx34buyt; __utmz=1.1560941612.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); xq_token_expire=Sun%20Jul%2014%202019%2020%3A22%3A34%20GMT%2B0800%20(China%20Standard%20Time); __utma=1.97938473.1556791189.1560941612.1560947495.2; aliyungf_tc=AQAAAO7F8FPkQw0AD8UhfeKtPJ3NgRwO; xq_a_token=31a9197f6c2fd63c431607c37609c83c41d3d9ae; xqat=31a9197f6c2fd63c431607c37609c83c41d3d9ae; xq_r_token=7f3562df50a068f73074c63850444d2fd9d92e0c; u=861562755715298; Hm_lvt_1db88642e346389874251b5a1eded6e3=1560349510,1560939212,1561627825,1562755862; Hm_lpvt_1db88642e346389874251b5a1eded6e3=1562765424'

协议交互的过程

GET /stock/search.json?code=sogo&size=3&page=1 HTTP/1.1
Host: xueqiu.com
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: application/json, text/plain, */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
elastic-apm-traceparent: 00-f680d3d81710bffc3ca33ad962f6dd47-86f58e210b618261-01
Referer: https://xueqiu.com/k?q=sogo
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7
Cookie: _ga=GA1.2.97938473.1556791189; device_id=c15c898fa623317fdaa696b5b25ea4e6; s=by11ypznnb; bid=18a1bec4795f9c5967fd96c6a12e9fb0_jx34buyt; __utmz=1.1560941612.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); xq_token_expire=Sun%20Jul%2014%202019%2020%3A22%3A34%20GMT%2B0800%20(China%20Standard%20Time); __utma=1.97938473.1556791189.1560941612.1560947495.2; aliyungf_tc=AQAAAO7F8FPkQw0AD8UhfeKtPJ3NgRwO; xq_a_token=31a9197f6c2fd63c431607c37609c83c41d3d9ae; xqat=31a9197f6c2fd63c431607c37609c83c41d3d9ae; xq_r_token=7f3562df50a068f73074c63850444d2fd9d92e0c; u=861562755715298; Hm_lvt_1db88642e346389874251b5a1eded6e3=1560349510,1560939212,1561627825,1562755862; Hm_lpvt_1db88642e346389874251b5a1eded6e3=1562764650

HTTP/1.1 200 OK
Date: Wed, 10 Jul 2019 13:18:19 GMT
Content-Type: application/json;charset=UTF-8
Content-Length: 222
Connection: keep-alive
Server: openresty/1.11.2.4
Trace-Id: e96f0865496e6acc
X-Application-Context: application:production
Cache-Control: private, no-store, no-cache, must-revalidate, max-age=0
P3P: "CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT""
Strict-Transport-Security: max-age=31536000

https://www.google.com/search?q=get+post+%E5%8C%BA%E5%88%AB&oq=get+post+%E5%8C%BA%E5%88%AB&aqs=chrome..69i57j69i64.3112j0j7&sourceid=chrome&ie=UTF-8

手工拼装http

localhost:~ seveniruby$ nc www.baidu.com 80
GET / HTTP/1.0
Host: www.baidu.com

HTTP/1.0 200 OK
Accept-Ranges: bytes
Cache-Control: no-cache
Content-Length: 14615
Content-Type: text/html
Date: Wed, 10 Jul 2019 14:00:20 GMT
Etag: "5d0888c3-3917"
Last-Modified: Tue, 18 Jun 2019 06:46:27 GMT
P3p: CP=" OTI DSP COR IVA OUR IND COM "
Pragma: no-cache
Server: BWS/1.1
Set-Cookie: BAIDUID=A27CD1289379B8280B0B2A26E2699F25:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
Set-Cookie: BIDUPSID=A27CD1289379B8280B0B2A26E2699F25; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
Set-Cookie: PSTM=1562767220; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
Vary: Accept-Encoding
X-Ua-Compatible: IE=Edge,chrome=1

<!DOCTYPE html><!--STATUS OK-->
<html>
<head>

常见面试题

  • GET POST区别
  • session与cookie的区别

代理

charles的rewrite功能可以实现mock与数据的解依赖

课后作业

  • 用curl命令发起对百度的一个搜索请求,修改header,在里面加上自己的名字,比如xxx@hogwarts
  • 用rewrite修改下股票的价格,把股价放大很多倍
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 16 条回复 时间 点赞

作业1

-----------------------------------分割线

作业2

作业1

作业2

curl http://www.baidu.com -H 'test:huahua'  -v

* About to connect() to www.baidu.com port 80 (#0)
* Trying 180.101.49.12...
* Connected to www.baidu.com (180.101.49.12) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: www.baidu.com
> Accept: */*
> test:huahua
>

用curl命令发起对百度的一个搜索请求,修改header,在里面加上自己的名字,比如xxx@hogwarts

curl http://www.baidu.com -H 'test:lijun@hogwarts' -v


用rewrite修改下股票的价格,把股价放大很多倍

吐槽一下自己的蠢,股票价格显示230.30,我rewrite230.30,修改不了,折腾半天,最后发现接口里返回的是230.3

作业1

作业2

作业一

curl -v www.baidu.com -H "Author: zzw"

作业二

作业1:

curl -v www.baidu.com -H 'test:harry@Hogwarts' -v

作业2:

作业1:

url -v --silent  www.baidu.com/s -H wd:霍格沃茨 -H name:chad@Hogwarts | more

作业2: 用rewrite修改下股票的价格,把股价放大很多倍

作业1

作业2

作业1

curl命令发起对百度的一个搜索请求,修改header,在里面加上自己的名字,比如xxx@hogwarts
curl -v www.baidu.com -H 'test:erin@hogwarts'


作业2

rewrite修改下股票的价格,把股价放大很多倍

curl 'https://www.baidu.com' -H 'lalalalalal@testerhome' -vvv

作业一
curl -H 'name:natume@hogwarts' -v http://www.baidu.com/

作业二

作业一

作业二

作业一
·curl http://www.baidu.com/s?wd=mp3 -H user-agent:test-mm@163.com -v -o a.txt

·作业二

[root@edujia ~]# curl http://www.baidu.com -H 'test:wuyanzu@hogwarts'  -v
* About to connect() to www.baidu.com port 80 (#0)
* Trying 61.135.169.121...
* Connected to www.baidu.com (61.135.169.121) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: www.baidu.com
> Accept: */*
> test:wuyanzu@hogwarts
>
< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
< Connection: Keep-Alive
< Content-Length: 2381
< Content-Type: text/html
< Date: Wed, 28 Aug 2019 07:34:15 GMT
< Etag: "588604c4-94d"
< Last-Modified: Mon, 23 Jan 2017 13:27:32 GMT
< Pragma: no-cache
< Server: bfe/1.0.8.18
< Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/
<
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>&copy;2017&nbsp;Baidu&nbsp;<a href=http://www.baidu.com/duty/>使用百度前必读</a>&nbsp; <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a>&nbsp;京ICP证030173号&nbsp; <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>
* Connection #0 to host www.baidu.com left intact
需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up