【原創】Linux基礎之curl

http請求過程以下:css

# curl -v http://www.baidu.com
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* About to connect() to www.baidu.com port 80 (#0)
* Trying 220.181.112.244...
* Connected to www.baidu.com (220.181.112.244) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: www.baidu.com
> 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: Wed, 16 Jan 2019 13:21:06 GMT
< Etag: "588604c8-94d"
< Last-Modified: Mon, 23 Jan 2017 13:27:36 GMT
< Pragma: no-cache
< Server: bfe/1.0.8.18
< Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/
<
{ [data not shown]
100 2381 100 2381 0 0 105k 0 --:--:-- --:--:-- --:--:-- 110k
* Connection #0 to host www.baidu.com left intact
<!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>
...html

工做中常常須要模擬http請求(好比任意修改header和body),curl很是好用,能夠經過服務器

curl -hdom

常看詳細的參數列表,下面列一些經常使用參數:curl

-v, --verbose Make the operation more talkativepost

顯示詳細的request和response信息,主要是header、狀態碼等ui

-u, --user USER[:PASSWORD] Server user and passwordurl

指定登錄帳號和密碼,-u user:password代理

-X, --request COMMAND Specify request command to useorm

指定Method,好比Get、Post、Put、Delete等,-X GET

-x, --proxy [PROTOCOL://]HOST[:PORT] Use proxy on given port

指定代理服務器和端口

-o, --output FILE Write output to <file> instead of stdout

輸出內容到指定文件,下載時使用

-H, --header LINE Custom header to pass to server (H)

指定任何header,-H 'Cookie: anything'

-d, --data DATA HTTP POST data (H)

指定post的body,-d '{"name":"value"}'

還能夠經過-d指定一個文件的內容,好比 -d@/path/to/file

相關文章
相關標籤/搜索