curl命令模拟HTTPGETPOST请求
在 Linux 操作系统上对后端程序进⾏测试的时候,需要进⾏模拟连接或者书写测试脚本
curl是什么命令
curl
访问百度,通过GET⽅法请求
命令格式: curl protocol://address:port/url
curl www.baidu
curl www.baidu
<!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: View Code
获取天⽓数据,通过POST⽅法请求
命令格式:curl -d "args"  "protocol://address:port/url"
curl -d "city=dongguan&appkey=8010132dcf54491a4eaa387f4db61774""way.jd/he/freeweather"
curl -d "city=dongguan&appkey=8010132dcf54491a4eaa387f4db61774""way.jd/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":"东风"}}, View Code
这种⽅法是参数直接在header⾥⾯的
如果将输出指定到⽂件可以通过重定向进⾏操作
命令格式:curl -H "Content-Type:application/json" -X POST --data (json.data) URL
curl -H "Content-Type:application/json" -X POST --data '{"message": "sunshine"}' localhost:8000/
这种⽅法是json数据直接在body⾥⾯的

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。