服务器端

使用nc监听本地端口,可以事先用curl访问一下百度,将返回的报文放在baidu_return_data文件里面

➜  nc_cmd nc -l 80 < baidu_return_data

客户端

  1. 使用curl访问
➜  ~ curl http://127.0.0.1 -v
* Rebuilt URL to: http://127.0.0.1/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1
> User-Agent: curl/7.54.0
> Accept: */*
>
< 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: Sun, 23 Dec 2018 04:48:30 GMT
< Etag: "588604dc-94d"
< Last-Modified: Mon, 23 Jan 2017 13:27:56 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>
* transfer closed with 2 bytes remaining to read
* stopped the pause stream!
* Closing connection 0
curl: (18) transfer closed with 2 bytes remaining to read
  1. 使用nc构造请求文件访问
➜  nc_cmd nc 127.0.0.1 80 < baidu_get
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: Sun, 23 Dec 2018 04:48:30 GMT
Etag: "588604dc-94d"
Last-Modified: Mon, 23 Jan 2017 13:27:56 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>

使用nc和curl模拟http服务器和客户端相关推荐

  1. Linux网络故障排查命令(ifconfig、ping、telnet、netstat、lsof、nc、curl、tcpdump)

    目录 ifconfig -s,显示网卡信息的精简列表 -a.up.down 将IP地址绑定到某个网卡,以及解绑操作 ping telnet netstat lsof nc 模拟一个服务器程序和客户端程 ...

  2. CURL模拟请求(get/post)

    [先知] http协议是客户端和服务端数据交互而定的规范. 具有如下特点:1.一般是基于B/S结构访问.2.无状态服务端没有记忆功能,不能识别客户端.3.无连接主要是在说http 1.0,它是短连接, ...

  3. php多线程模拟请求,浅谈php使用curl模拟多线程发送请求

    每个PHP文件的执行是单线程的,但是php本身也可以用一些别的技术实现多线程并发比如用php-fpm进程,这里用curl模拟多线程发送请求.php的curl多线程是通过不断调用curl_multi_e ...

  4. php post 二维数组,php curl模拟post请求和提交多维数组的示例代码

    这篇文章主要介绍了php curl模拟post请求和提交多维数组的示例代码,需要的朋友可以参考下 下面一段代码给大家介绍php curl模拟post请求的示例代码,具体代码如下: 'tanteng' ...

  5. curl服务器文件,curl 向远程服务器传输file文件

    public function upload(){ //获取上传文件信息,文件名称以自己实际上传文件名称为准 $fileinfo = $_FILE['filename']; //请求参数,依据商户自己 ...

  6. 【php】curl模拟登录抓取页面信息

    [php]curl模拟登录抓取页面信息 在本项目中,使用php抓取四川大学综合教务网站的成绩信息.课程信息以及登录用户的基本资料,解析数据并存入数据库,以实现对所得信息的进一步分析,并呈现给用户. 本 ...

  7. php读取cookie文件,PHP读取CURL模拟登录时生成Cookie文件的方法,_PHP教程

    PHP读取CURL模拟登录时生成Cookie文件的方法, 本文实例讲述了PHP读取CURL模拟登录时生成Cookie文件的方法.分享给大家供大家参考.具体实现方法如下: 在使用PHP中的CURL模拟登 ...

  8. php中curl模拟post提交多维数组

    今天需要用curl模拟post提交参数,请求同事提供的一个接口:但是传递的参数中,有一个参数的值为数组,用普通的curl post代码提交,会报错误 PHP Notice:  Array to str ...

  9. 使用PHP CURL 模拟HTTP实现在线请求工具-toolfk程序员工具网

    本文要推荐的[ToolFk]是一款程序员经常使用的线上免费测试工具箱,ToolFk 特色是专注于程序员日常的开发工具,不用安装任何软件,只要把内容贴上按一个执行按钮,就能获取到想要的内容结果.Tool ...

最新文章

  1. HDU - 1358 Period(KMP的next数组求最小循环节)
  2. [react] 如何解决引用类型在pureComponent下修改值的时候,页面不渲染的问题?
  3. AngualrJS之服务器端通信
  4. byte[]和InputStream的相互转换
  5. 你会和丑且家境不好,但对你好的男孩结婚吗?
  6. MFC对话框程序中添加工具栏及工具栏上的Button响应UPDATE_COMMAND_UI消息
  7. 腾讯再投500亿元资金助力共同富裕;数学家将π计算到62.8万亿位;Go 1.17正式发布|极客头条...
  8. AppCode开发,一个智能开发环境
  9. mod mpm event php7.1,CentOS 7 安裝 PHP-FPM 及使用 mod_mpm_event
  10. 100以内的三连加减法JAVA_100以内的加减法巧算(转)
  11. 超简单一行代码实现应用双开,仿照微信双开、QQ双开等实现app应用双开,即采用Android插件化开发在免安装情况下加载使用原生app
  12. python安装库的命令-免费足球现场直播直播
  13. 天牛须算法(BAS)python实现
  14. 我的Spring入门
  15. nginxgrafana监控面板显示nodatatoshow
  16. 01组团队项目-Alpha冲刺-1/6
  17. Webug靶场之旅——显错注入
  18. 课程表 (leetcode)
  19. 开发者的瑞士军刀Eolink,目测要火
  20. DDD 兴起的原因以及与微服务的关系

热门文章

  1. GitHub网站排版混乱并且速度慢的问题
  2. C#分割字符串。歌词
  3. 中国工程科学:无人驾驶安全风险的识别与度量研究
  4. Day03顺序表的结构设计2.0
  5. 酒有七不喝,财有三不发,话有三不说,忙有三不帮,债有三不欠,碗有三不端,邻有三不比,亲友三不走!
  6. 论文简读 MetNet: A Neural Weather Model for Precipitation Forecasting
  7. 关于使用西电2019年3月修订版Latex毕业论文模板的记录贴
  8. DIAsource/艾美捷——肾上腺皮质激素相关研究
  9. Metasploit攻击linux实例
  10. PR开场片头模板 枪击爆炸效果短视频开场logo展示PR模板