在 Linux 操作系统上对后端程序进行测试的时候,需要进行模拟连接或者书写测试脚本

curl

访问百度,通过GET方法请求

命令格式: curl protocol://address:port/url

curl http://www.baidu.com

<!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>

获取天气数据,通过POST方法请求

命令格式:curl -d "args"  "protocol://address:port/url"

curl -d "city=dongguan&appkey=8010132dcf54491a4eaa387f4db61774" "https://way.jd.com/he/freeweather"

{"code":"10000","charge":false,"msg":"查询成功","result":{"HeWeather5":[{"now":{"hum":"67","vis":"7","pres":"1018","pcpn":"0","fl":"9","tmp":"16","cond":{"txt":"多云","code":"101"},"wind":{"sc":"3-4","spd":"12","deg":"96","dir":"东风"}},"suggestion":{"uv":{"txt":"紫外线强度较弱,建议出门前涂擦SPF在12-15之间、PA+的防晒护肤品。","brf":"弱"},"cw":{"txt":"较适宜洗车,未来一天无雨,风力较小,擦洗一新的汽车至少能保持一天。","brf":"较适宜"},"trav":{"txt":"天气较好,但丝毫不会影响您出行的心情。温度适宜又有微风相伴,适宜旅游。","brf":"适宜"},"air":{"txt":"气象条件对空气污染物稀释、扩散和清除无明显影响,易感人群应适当减少室外活动时间。","brf":"中"},"comf":{"txt":"白天不太热也不太冷,风力不大,相信您在这样的天气条件下,应会感到比较清爽和舒适。","brf":"舒适"},"drsg":{"txt":"建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。","brf":"较舒适"},"sport":{"txt":"天气较好,赶快投身大自然参与户外运动,尽情感受运动的快乐吧。","brf":"适宜"},"flu":{"txt":"各项气象条件适宜,无明显降温过程,发生感冒机率较低。","brf":"少发"}},"aqi":{"city":{"no2":"27","o3":"71","pm25":"38","qlty":"良","so2":"11","aqi":"54","pm10":"47","co":"1"}},"basic":{"city":"东莞","update":{"loc":"2017-12-05 17:52","utc":"2017-12-05 09:52"},"lon":"113.7462616","id":"CN101281601","cnty":"中国","lat":"23.04623795"},"daily_forecast":[{"date":"2017-12-05","pop":"0","hum":"46","uv":"6","vis":"16","astro":{"ss":"17:41","mr":"19:32","ms":"08:13","sr":"06:52"},"pres":"1022","pcpn":"0.0","tmp":{"min":"15","max":"20"},"cond":{"txt_n":"多云","code_n":"101","code_d":"103","txt_d":"晴间多云"},"wind":{"sc":"微风","spd":"3","deg":"0","dir":"无持续风向"}},{"date":"2017-12-06","pop":"0","hum":"41","uv":"6","vis":"20","astro":{"ss":"17:41","mr":"20:36","ms":"09:16","sr":"06:52"},"pres":"1019","pcpn":"0.0","tmp":{"min":"14","max":"22"},"cond":{"txt_n":"多云","code_n":"101","code_d":"101","txt_d":"多云"},"wind":{"sc":"微风","spd":"5","deg":"0","dir":"无持续风向"}},{"date":"2017-12-07","pop":"0","hum":"47","uv":"6","vis":"20","astro":{"ss":"17:41","mr":"21:40","ms":"10:14","sr":"06:53"},"pres":"1019","pcpn":"0.0","tmp":{"min":"14","max":"23"},"cond":{"txt_n":"多云","code_n":"101","code_d":"100","txt_d":"晴"},"wind":{"sc":"微风","spd":"9","deg":"0","dir":"无持续风向"}},{"date":"2017-12-08","pop":"0","hum":"36","uv":"6","vis":"20","astro":{"ss":"17:42","mr":"22:42","ms":"11:06","sr":"06:54"},"pres":"1022","pcpn":"0.0","tmp":{"min":"11","max":"20"},"cond":{"txt_n":"晴","code_n":"100","code_d":"100","txt_d":"晴"},"wind":{"sc":"微风","spd":"9","deg":"351","dir":"北风"}},{"date":"2017-12-09","pop":"0","hum":"27","uv":"6","vis":"20","astro":{"ss":"17:42","mr":"23:42","ms":"11:53","sr":"06:54"},"pres":"1022","pcpn":"0.0","tmp":{"min":"10","max":"19"},"cond":{"txt_n":"晴","code_n":"100","code_d":"100","txt_d":"晴"},"wind":{"sc":"微风","spd":"6","deg":"0","dir":"无持续风向"}},{"date":"2017-12-10","pop":"0","hum":"28","uv":"6","vis":"20","astro":{"ss":"17:42","mr":"09:47","ms":"12:36","sr":"06:55"},"pres":"1021","pcpn":"0.0","tmp":{"min":"10","max":"21"},"cond":{"txt_n":"晴","code_n":"100","code_d":"100","txt_d":"晴"},"wind":{"sc":"微风","spd":"4","deg":"0","dir":"无持续风向"}},{"date":"2017-12-11","pop":"0","hum":"31","uv":"6","vis":"20","astro":{"ss":"17:42","mr":"00:38","ms":"13:16","sr":"06:56"},"pres":"1022","pcpn":"0.0","tmp":{"min":"11","max":"22"},"cond":{"txt_n":"多云","code_n":"101","code_d":"100","txt_d":"晴"},"wind":{"sc":"微风","spd":"6","deg":"0","dir":"无持续风向"}}],"hourly_forecast":[{"date":"2017-12-05 19:00","pop":"0","hum":"32","pres":"1020","tmp":"17","cond":{"txt":"晴间多云","code":"103"},"wind":{"sc":"微风","spd":"16","deg":"43","dir":"东北风"}},{"date":"2017-12-05 22:00","pop":"0","hum":"36","pres":"1021","tmp":"17","cond":{"txt":"晴间多云","code":"103"},"wind":{"sc":"微风","spd":"14","deg":"41","dir":"东北风"}},{"date":"2017-12-06 01:00","pop":"0","hum":"36","pres":"1020","tmp":"15","cond":{"txt":"晴","code":"100"},"wind":{"sc":"微风","spd":"12","deg":"41","dir":"东北风"}},{"date":"2017-12-06 04:00","pop":"0","hum":"39","pres":"1020","tmp":"15","cond":{"txt":"晴间多云","code":"103"},"wind":{"sc":"微风","spd":"10","deg":"41","dir":"东北风"}},{"date":"2017-12-06 07:00","pop":"0","hum":"39","pres":"1021","tmp":"15","cond":{"txt":"晴间多云","code":"103"},"wind":{"sc":"微风","spd":"9","deg":"46","dir":"东北风"}},{"date":"2017-12-06 10:00","pop":"0","hum":"35","pres":"1021","tmp":"16","cond":{"txt":"晴间多云","code":"103"},"wind":{"sc":"微风","spd":"8","deg":"54","dir":"东北风"}},{"date":"2017-12-06 13:00","pop":"0","hum":"31","pres":"1019","tmp":"17","cond":{"txt":"晴间多云","code":"103"},"wind":{"sc":"微风","spd":"5","deg":"69","dir":"东北风"}},{"date":"2017-12-06 16:00","pop":"0","hum":"32","pres":"1017","tmp":"20","cond":{"txt":"晴间多云","code":"103"},"wind":{"sc":"微风","spd":"4","deg":"91","dir":"东风"}}],"status":"ok"}]}}

这种方法是参数直接在header里面的

如果将输出指定到文件可以通过重定向进行操作

命令格式:curl -H "Content-Type:application/json" -X POST --data (json.data) URL

curl -H "Content-Type:application/json" -X POST --data '{"message": "sunshine"}' http://localhost:8000/

这种方法是json数据直接在body里面的

更多 curl 用法或参数可使用 man 命令查看,亦可访问 https://curl.haxx.se/

[转]curl 命令模拟 HTTP GET/POST 请求的更多相关文章

  1. 在Linux上利用curl 命令模拟 HTTP GET/POST 请求

    本文系转载,原文地址:https://www.cnblogs.com/alfred0311/p/7988648.html 序言 在 Linux 操作系统上对后端程序进行测试的时候,需要进行模拟连接或者 ...

  2. curl 命令模拟 HTTP GET/POST 请求

    https://www.cnblogs.com/alfred0311/p/7988648.html

  3. Linux curl 命令模拟 POST/GET 请求

    Linux curl 命令模拟 POST/GET 请求   本文链接:https://blog.csdn.net/sunboy_2050/article/details/82156402 curl 命 ...

  4. 使用curl 命令模拟POST/GET请求

    https://blog.csdn.net/u012340794/article/details/71440604 curl命令是一个利用URL规则在命令行下工作的文件传输工具.它支持文件的上传和下载 ...

  5. Linux命令发送Http GET/POST请求

    Get请求 curl命令模拟Get请求: 1.使用curl命令: curl "http://www.baidu.com" 如果这里的URL指向的是一个文件或者一幅图都可以直接下载到 ...

  6. 上curl java 模拟http请求

    最近,我的项目要求java模拟http请求,获得dns解决 tcp处理过的信息特定的连接. java api提供urlConnection apache提供的httpClient都不能胜任该需求,二次 ...

  7. Linux命令模拟Http的get或post请求

    Http请求指的是客户端向服务器的请求消息,Http请求主要分为get或post两种,在Linux系统下可以用curl和wget命令来模拟Http的请求. get请求: 1.使用curl命令: cur ...

  8. php封装curl,模拟POST和GET请求HTTPS请求

    <?php /** * @title 封装代理请求 * @author victor **/ class ApiRequest { /** * curl提交数据 * @param String ...

  9. curl java 模拟http请求

    curl java 模拟http请求 直接上代码: public static void main(String args[]) throws Exception { String url = &qu ...

随机推荐

  1. Vi 和 Vim 编辑器详细使用方法

    学习linux的一项必会技能,熟练使用vi/vim编辑器那便最重要的了.不过一堆操作看的也是太头疼了,以下整理了些常用到的命令. 工作模式 vi编辑界面有三种不同的工作模式,分别为命令模式.输入模式. ...

  2. 【转】Vsftpd-3.0.2服务器arm-linux移植—mini2440开发板

    Vsftpd-3.0.2服务器arm-linux移植—mini2440开发板 开发板:mini2440(2011.04.21)环境:ubuntu9.10 为方便的将文件上传到开发板,采用vsftpd, ...

  3. Python 软件安装

    安装Python解释器 Python目前已支持所有主流操作系统,在Linux,Unix,Mac系统上自带Python环境,在Windows系统上需要安装一下,超简单 打开官网https://www.p ...

  4. rsa公钥和私钥到底哪个才是用来加密,哪个用来解密?

    本文转自:91博客:原文地址:http://www.9191boke.com/138589019.html 公钥和私钥在一些银行系统.第三方支付系统SDK中经常会遇到,刚接触公钥私钥的朋友们估计很难区 ...

  5. c++练手项目:英语单词拼写测试程序

    代码比较简单.基本的思路是从文本文件中按行读取数据,数据结构为“hello-你好”.前面是英语,后面是中文,中间用“-”连接.程序通过查找连词符的位置来分割中文和英文.再通过和用户输入的单词进行比较判 ...

  6. myslq数据库用union all查询出现 #1271 - Illegal mix of collations for operation 'UNION'

    出现 #1271 - Illegal mix of collations for operation 'UNION' 的原因是两个字符编码不匹配造成的. 我遇到的是  utf8_general_ci ...

  7. Apache Shiro<=1.2.4反序列化RCE漏洞

    介绍:Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授权.密码和会话管理. 漏洞原因:因为shiro对cookie里的rememberme字段进行了反序列化,所以如果知道了 ...

  8. A - Happy Birthday, Polycarp!

    Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4) A. Happy Birthday, Polyc ...

  9. tbls ci 友好的数据库文档化工具

    tbls 是用golang 编写的数据库文档化工具,当前支持的数据库有pg.mysql.bigquery 此工具同时提供了变更对比.lint 校验,生成是markdown格式的 简单使用 安装 mac ...

  10. 【树形DP】骑士

    骑士 题目描述 \(Z\)国的骑士团是一个很有势力的组织,帮会中汇聚了来自各地的精英.他们劫富济贫,惩恶扬善,受到社会各界的赞扬. 最近发生了一件可怕的事情,邪恶的\(Y\)国发动了一场针对Z国的侵略 ...