1 Overview
- I have come across a lot of server-side debugging interface testing, eventually fell on this place
- Short answer introduce the use of curl
- Try step by step, because I'm not familiar with
- Probably command mentioned
- curl
- curl -v
- curl -s
- curl -i
- curl -X
- curl -H
- curl -d
2. curl
- CommandLine Uniform Resource Locator
- Official website
https://curl.haxx.se/
- characteristic
- This is not to say
- After all, it is in my hands, just a simple command-line tool
3. Command
help
# 这个命令如果能运行, 说明 机器上确实有 curl # 具体内容不少, 建议在对 curl 有一定认知之后, 再去尝试阅读 > curl --help
- Simple mode and cumbersome mode
- Simple mode
command
# curl 访问 url 的时候, 建议带上协议 # 如果不带的话, 默认是 http > curl 'http://www.baidu.com'
- result
return
# 勉强对齐了一下 # 结果类似一个表格, 前两行是表头, 最后一行, 是结果 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 2381 100 2381 0 0 50659 0 --:--:-- --:--:-- --:--:-- 50659 # 后面是 baidu 的html, 就不列举了
- Sorry, this statistical information, leave a pit bar
If you do not want this statistics, you can use the following command
> curl -s 'http://www.baidu.com'
- Cumbersome mode
command
> curl -v 'http://www.baidu.com'
- result
return
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 61.135.169.121... * TCP_NODELAY set * Connected to www.baidu.com (61.135.169.121) port 80 (#0) # 这一部分, 是 请求 > GET / HTTP/1.1 > Host: www.baidu.com > User-Agent: curl/7.63.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: Fri, 16 Aug 2019 12:48:41 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=/ < { [2381 bytes data] 100 2381 100 2381 0 0 74406 0 --:--:-- --:--:-- --:--:-- 74406 # 这一行, 是请求页面的内容, 略 # 这一行是啥, 我也不太清楚了 * Connection #0 to host www.baidu.com left intact
- If you only care about return
You can use the following command
> curl -i 'http://www.baidu.com'
- Simple mode
- Request method
command
> curl -vs -X GET 'http://www.baidu.com'
- result
- And complicated patterns are basically the same
- The default request method is GET
- GET can be replaced by other methods
- Request header
command
> curl -is -X GET -H 'Content-Type: text/html' 'http://www.baidu.com'
- Request body
command
> curl -vs -X GET -H 'Content-Type: text/html' -d '{"key": "value"}' 'http://www.baidu.com'
4. Finally
- I do not speak good feeling
- In fact, these commands can alluded
- Is the basic request to see the request, see Response, given request mode setting request header, request body disposed
- Related things, I like to talk about and do not know how to start
- http relevant
- curl results
- That statistic
- Such as connection process in verbose mode
- In fact, this thing has a lot of places you can use
- Have the opportunity, I will try to do some other explanation.
- In fact, these commands can alluded
- ref
curl Guide
https://www.jianshu.com/p/fc0eb6c60816
Official online book called everything-curl, written in great detail, but they are in English.