- curl不加参数
[root@xhs html]# curl http://xiaohuasheng.net
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>curl</title>
</head>
<body>
<h1>curl学习测试</h1>
</body>
</html>
[root@xhs html]#
- curl工具获取web服务器支持的方法
参数介绍
-i :显示响应中的HTTP请求头和数据信息
-I:只显示响应中的HTTP请求头信息
-X:指定请求HTTP方法(经测试,大多数网站返回不了,感觉没啥用)
[root@xhs html]# curl -I -X OPTIONS 52download.cn
HTTP/1.1 200 OK
Date: Fri, 18 Sep 2020 17:48:39 GMT
Server: Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/5.6.28
Content-Length: 2513
Content-Type: text/html; Charset=gb2312
- curl提交post请求
参数介绍:
-d:表示提交post参数
-X:post指定使用http post方法
举例“:
curl -d "username=admin&password=admin" -X POST http://www.xxx.com/login.php
演示:
[root@xhs ~]# curl -i -X POST -d "staticpage=https%3A%2F%2Fwww.baidu.com%2Fcache%2Fuser%2Fhtml
%2Fv3Jump.html&charset=UTF-8&token=64809ae6cc6ae4e44848575f8054c388&tpl=mn&subpro=&apiver=v3&
tt=1600487701952&codestring=&safeflg=0&u=https%3A%2F%2Fwww.baidu.com%2F&isPhone=
&detect=1&gid=0E8070A-C171-48C4-AA4F-665E32BF8036&quick_user=0
&logintype=dialogLogin&logLoginType=pc_loginDialog&idc=&loginmerge=true&mkey=&splogin=rate&
username=18341320198&password=eLblxs3fkBi5SP80etIJoyPi%2Fw%2Byw11q6F7y4mh02uyuBCFCmDa9P23
grRyqfUeB4E3qG9z6ueLGvMCviOKKBOfklZsc2USJAqNGkN
XENnJeUpzFArswTE9QgbvIQ%2B0%2FdabW%2BwkXKxzhS0ADR8dVAL
tbb4nO2dgh8CGZEtIwsHI%3D&mem_pass=on
&rsakey=dbBzuuqcBHBfNFpZmc9A73O2ILY6EnWo&crypttype=12&ppui_logintime=1789&countrycode=&fp_uid=&fp_info=&loginversion=v4&supportdv=1&ds=ODYBh0YgOyQSSrFFUX8M6D6Ek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BtUwbqMah0yfhlGFxin
8DfQKbHtUPdI3b0qIw7SiPV9IfnwFQ%3D&tk=9633r8OgxYetkYbkrKNEZwoRvn5XRhlw3113ni3SW
uWzqq%2FWm7%2FtwPgVdbAp8CVP9WOhWFdvTvobeaJk7N4BzH0d6g%3D%3D&dv=tk0.031564230448258181600487700503%40llq0Ic5kqGJ2pD7Q0h6JjHIp9ACf2SCQjQRgJi6apdEF%7EiD6Eb5kqGJ2pD7Q0h6JjHIp9ACf2SCQj
%7ENC9fOgjiEm%7Ef4f9buqo46qfDF%7EiD6NG96qf5p7h6WOFAIQHCQh6IpbS4JjHOC93RWlBt8JbCccKzcxI2NEHhxqi4F%7Ei5kUSBqvOnG%
7E51qf46Ig9ksf4kAxDksQDk2y46N%7E4kAy9fR%7E4kI%7E4%7E__iqQKr7xRr4v5ij-O-RcNapVErIcNgjd5iSQta73Ea3cE8A_-qv4m%7EDNYYE7ucLE22Bi0Ojbor7y6SXfVj7%2BB4iuZO
%2Bf7FUDWABtt%2FWWQqHKVfXShow more" "https://passport.baidu.com/v2/api/?login"
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Access-Control-Expose-Headers: Trace-ID
Cache-Control: public
Connection: keep-alive
Content-Security-Policy-Report-Only: object-src 'none'; script-src 'self' 'unsafe-inline' 'unsafe-eval' 'report-sample' wappass.baidu.com:* passport.baidu.com:* wappass.bdimg.com:* passport.bdimg.com:* hm.baidu.com:* fe.bdimg.com:* msg.baidu.com:* pdc.baidu.com:* img.baidu.com:* openapi.baidu.com:* res.wx.qq.com:* qqq.gtimg.cn:* s.bdstatic.com:* ufosdk.baidu.com:* qapm.baidu.com:* libs.baidu.com:* ext.baidu.com:* apps.baidu.com:* s3.pstatp.com:* tb2.bdstatic.com:* b.bdstatic.com:* msg.baidu.com:* www.baidu.com:* po.srf.baidu.com:* pan.baidu.com:* play.baidu.com:* tb1.bdstatic.com:* dup.baidustatic.com:* static.tieba.baidu.com:* gss2.bdstatic.com:* blob: baiduboxapp: bootupbaiduhd: ; report-uri https://report-uri.baidu.com/report?app=passport;
Content-Type: text/html
Date: Sat, 19 Sep 2020 04:03:52 GMT
Etag: w/"eRbD5vOkR1kfcOR1JqGuiefCxX82tM2i:1600488232"
Expires: 0
Last-Modified: Sat, 19 Sep 2020 04:03:52 4SepGMT
P3p: CP=" OTI DSP COR IVA OUR IND COM "
P3p: CP=" OTI DSP COR IVA OUR IND COM "
Pragma: public
Referrer-Policy: no-referrer-when-downgrade, strict-origin-when-cross-origin
Server: Apache
Set-Cookie: PASSID=9IalQc; expires=Fri, 20-Sep-2019 04:03:52 GMT; path=/; domain=passport.baidu.com; httponly
Set-Cookie: UBI=fi_PncwhpxZ%7ETaJc1eMrOE59e5cbm7-2aAU; expires=Wed, 06-Dec-2028 04:03:52 GMT; path=/; domain=passport.baidu.com; httponly
Set-Cookie: BAIDUID=46790CEED190B5783D352462C6C57A1E:FG=1; expires=Sun, 19-Sep-21 04:03:52 GMT; max-age=31536000; path=/; domain=.baidu.com; version=1
Strict-Transport-Security: max-age=31536000
Trace-Id:
Tracecode: 02328248780393516810091912
Tracecode: 02328248780283588874091912
Vary: Accept-Encoding
Vary: Accept-Encoding
Transfer-Encoding: chunked
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<script type="text/javascript" nonce="utCzXhljkGcBTwqg">
var href = decodeURIComponent("https:\/\/www.baidu.com\/cache\/user\/html\/v3Jump.html")+"?"
var accounts = '&accounts='
href += "err_no=100023&callback=&codeString=&isslide=&userName=&phoneNumber=&mail=&hao123Param=&u=&tpl=&secstate=&gotourl=&authtoken=&loginproxy=&resetpwd=&vcodetype=&lstr=<oken=&bckv=&bcsync=&bcchecksum=&code=&bdToken=&realnameswitch=&setpwdswitch=&bctime=&bdstoken=&authsid=&jumpset=&appealurl=&realnameverifyemail=0&traceid=&realnameauthsid=&bind_mobile_token=&upgrade_mobile_token=&upgrade_mobile=&guide_upgrade_mobile=&scscene=&scnewuser=&secauthsid=&secbdstoken=&authid=" + accounts;
if(window.location){
window.location.replace(href);
}else{
document.location.replace(href);
}
</script>
</body>
</html>
<!--02328248780283588874091912-->
<script> var _trace_page_logid = 0232824878; </script>
需要注意的是,-d后面那些参数是以及对应请求的url是我去chrome里面自己复制出来的,见下图:
post请求的url
还有这一堆参数
- curl设置cookie值
curl --cookie "xxxxxxxxx" http://www.xxx.com
[root@xhs ~]# curl --cookie "BIDUPSID=5448C4607731035CDFD3DC6BD127A059; PSTM=1587486548; BAIDUID=5448C4607731035CAC42E7B758E4BF64:FG=1; BD_UPN=12314753; BD_HOME=1; delPer=0; BD_CK_SAM=1; PSINO=1; shifen[6938291_19284]=1600447561; BCLID=8440525329093301557; BDSFRCVID=32COJexroG3oGcJrjycQ-VRI_gKKHJQTDYLE3ONZ67Yl5X-VN4vIEG0PtjcEHMA-2ZlgogKK0gOTH6KF_2uxOjjg8UtVJeC6EG0Ptf8g0M5; H_BDCLCKID_SF=JJkO_D_atKvjDbTnMITHh-F-5fIX5-RLfbAH5h7F54nKDp0RhUJjyRDq2fbIel5NWGOMahvdWfjxsMTsQjbcXlTBjnrQtlkLQe_JLqTN3KJmfbcnQf7YLDrXWxvM2-biWbRM2MbdJqvP_IoG2Mn8M4bb3qOpBtQmJeTxoUJ25DnJhhCGe4bK-TrBDNAe3H; BDRCVFR[nuO7wD_8FJc]=qdOo65HpBYTTh7znWc8mvqV; BDORZ=FFFB88E999055A3F8A630C64834BD6D0; H_PS_645EC=2733QaH3fWnLazoCVVv4zRA2ekezhF4ROsA%2FEj%2FBp4bTODrCQ84ti6ctMExq5myg9U%2FG7a1B26E; H_PS_PSSID=32617_1460_32748_31254_7579_32706_7624_32115_7564_26350; BDUSS=VZkSnBmbmo2RHFHZ1Z6R3RYOW5TRlZndWFzRXdxT3lBfnBucFJObjluekREbzFmRVFBQUFBJCQAAAAAAAAAAAEAAADNJ-pSt-i~8bXE0KG7qMn6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMOBZV~DgWVfY; BDUSS_BFESS=VZkSnBmbmo2RHFHZ1Z6R3RYOW5TRlZndWFzRXdxT3lBfnBucFJObjluekREbzFmRVFBQUFBJCQAAAAAAAAAAAEAAADNJ-pSt-i~8bXE0KG7qMn6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMOBZV~DgWVfY" http://www.baidu.com -I
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: keep-alive
Content-Length: 277
Content-Type: text/html
Date: Sat, 19 Sep 2020 04:49:25 GMT
Etag: "575e1f60-115"
Last-Modified: Mon, 13 Jun 2016 02:50:08 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
帮助文档附上
[root@xhs ~]# curl --help
Usage: curl [options...] <url>
Options: (H) means HTTP/HTTPS only, (F) means FTP only
--anyauth Pick "any" authentication method (H)
-a, --append Append to target file when uploading (F/SFTP)
--basic Use HTTP Basic Authentication (H)
--cacert FILE CA certificate to verify peer against (SSL)
--capath DIR CA directory to verify peer against (SSL)
-E, --cert CERT[:PASSWD] Client certificate file and password (SSL)
--cert-type TYPE Certificate file type (DER/PEM/ENG) (SSL)
--ciphers LIST SSL ciphers to use (SSL)
--compressed Request compressed response (using deflate or gzip)
-K, --config FILE Specify which config file to read
--connect-timeout SECONDS Maximum time allowed for connection
-C, --continue-at OFFSET Resumed transfer offset
-b, --cookie STRING/FILE String or file to read cookies from (H)
-c, --cookie-jar FILE Write cookies to this file after operation (H)
--create-dirs Create necessary local directory hierarchy
--crlf Convert LF to CRLF in upload
--crlfile FILE Get a CRL list in PEM format from the given file
-d, --data DATA HTTP POST data (H)
--data-ascii DATA HTTP POST ASCII data (H)
--data-binary DATA HTTP POST binary data (H)
--data-urlencode DATA HTTP POST data url encoded (H)
--delegation STRING GSS-API delegation permission
--digest Use HTTP Digest Authentication (H)
--disable-eprt Inhibit using EPRT or LPRT (F)
--disable-epsv Inhibit using EPSV (F)
-D, --dump-header FILE Write the headers to this file
--egd-file FILE EGD socket path for random data (SSL)
--engine ENGINGE Crypto engine (SSL). "--engine list" for list
-f, --fail Fail silently (no output at all) on HTTP errors (H)
-F, --form CONTENT Specify HTTP multipart POST data (H)
--form-string STRING Specify HTTP multipart POST data (H)
--ftp-account DATA Account data string (F)
--ftp-alternative-to-user COMMAND String to replace "USER [name]" (F)
--ftp-create-dirs Create the remote dirs if not present (F)
--ftp-method [MULTICWD/NOCWD/SINGLECWD] Control CWD usage (F)
--ftp-pasv Use PASV/EPSV instead of PORT (F)
-P, --ftp-port ADR Use PORT with given address instead of PASV (F)
--ftp-skip-pasv-ip Skip the IP address for PASV (F)
--ftp-pret Send PRET before PASV (for drftpd) (F)
--ftp-ssl-ccc Send CCC after authenticating (F)
--ftp-ssl-ccc-mode ACTIVE/PASSIVE Set CCC mode (F)
--ftp-ssl-control Require SSL/TLS for ftp login, clear for transfer (F)
-G, --get Send the -d data with a HTTP GET (H)
-g, --globoff Disable URL sequences and ranges using {} and []
-H, --header LINE Custom header to pass to server (H)
-I, --head Show document info only
-h, --help This help text
--hostpubmd5 MD5 Hex encoded MD5 string of the host public key. (SSH)
-0, --http1.0 Use HTTP 1.0 (H)
--ignore-content-length Ignore the HTTP Content-Length header
-i, --include Include protocol headers in the output (H/F)
-k, --insecure Allow connections to SSL sites without certs (H)
--interface INTERFACE Specify network interface/address to use
-4, --ipv4 Resolve name to IPv4 address
-6, --ipv6 Resolve name to IPv6 address
-j, --junk-session-cookies Ignore session cookies read from file (H)
--keepalive-time SECONDS Interval between keepalive probes
--key KEY Private key file name (SSL/SSH)
--key-type TYPE Private key file type (DER/PEM/ENG) (SSL)
--krb LEVEL Enable Kerberos with specified security level (F)
--libcurl FILE Dump libcurl equivalent code of this command line
--limit-rate RATE Limit transfer speed to this rate
-l, --list-only List only names of an FTP directory (F)
--local-port RANGE Force use of these local port numbers
-L, --location Follow redirects (H)
--location-trusted like --location and send auth to other hosts (H)
-M, --manual Display the full manual
--mail-from FROM Mail from this address
--mail-rcpt TO Mail to this receiver(s)
--mail-auth AUTH Originator address of the original email
--max-filesize BYTES Maximum file size to download (H/F)
--max-redirs NUM Maximum number of redirects allowed (H)
-m, --max-time SECONDS Maximum time allowed for the transfer
--metalink Process given URLs as metalink XML file
--negotiate Use HTTP Negotiate Authentication (H)
-n, --netrc Must read .netrc for user name and password
--netrc-optional Use either .netrc or URL; overrides -n
--netrc-file FILE Set up the netrc filename to use
-N, --no-buffer Disable buffering of the output stream
--no-keepalive Disable keepalive use on the connection
--no-sessionid Disable SSL session-ID reusing (SSL)
--noproxy List of hosts which do not use proxy
--ntlm Use HTTP NTLM authentication (H)
-o, --output FILE Write output to <file> instead of stdout
--pass PASS Pass phrase for the private key (SSL/SSH)
--post301 Do not switch to GET after following a 301 redirect (H)
--post302 Do not switch to GET after following a 302 redirect (H)
--post303 Do not switch to GET after following a 303 redirect (H)
-#, --progress-bar Display transfer progress as a progress bar
--proto PROTOCOLS Enable/disable specified protocols
--proto-redir PROTOCOLS Enable/disable specified protocols on redirect
-x, --proxy [PROTOCOL://]HOST[:PORT] Use proxy on given port
--proxy-anyauth Pick "any" proxy authentication method (H)
--proxy-basic Use Basic authentication on the proxy (H)
--proxy-digest Use Digest authentication on the proxy (H)
--proxy-negotiate Use Negotiate authentication on the proxy (H)
--proxy-ntlm Use NTLM authentication on the proxy (H)
-U, --proxy-user USER[:PASSWORD] Proxy user and password
--proxy1.0 HOST[:PORT] Use HTTP/1.0 proxy on given port
-p, --proxytunnel Operate through a HTTP proxy tunnel (using CONNECT)
--pubkey KEY Public key file name (SSH)
-Q, --quote CMD Send command(s) to server before transfer (F/SFTP)
--random-file FILE File for reading random data from (SSL)
-r, --range RANGE Retrieve only the bytes within a range
--raw Do HTTP "raw", without any transfer decoding (H)
-e, --referer Referer URL (H)
-J, --remote-header-name Use the header-provided filename (H)
-O, --remote-name Write output to a file named as the remote file
--remote-name-all Use the remote file name for all URLs
-R, --remote-time Set the remote file's time on the local output
-X, --request COMMAND Specify request command to use
--resolve HOST:PORT:ADDRESS Force resolve of HOST:PORT to ADDRESS
--retry NUM Retry request NUM times if transient problems occur
--retry-delay SECONDS When retrying, wait this many seconds between each
--retry-max-time SECONDS Retry only within this period
-S, --show-error Show error. With -s, make curl show errors when they occur
-s, --silent Silent mode. Don't output anything
--socks4 HOST[:PORT] SOCKS4 proxy on given host + port
--socks4a HOST[:PORT] SOCKS4a proxy on given host + port
--socks5 HOST[:PORT] SOCKS5 proxy on given host + port
--socks5-basic Enable username/password auth for SOCKS5 proxies
--socks5-gssapi Enable GSS-API auth for SOCKS5 proxies
--socks5-hostname HOST[:PORT] SOCKS5 proxy, pass host name to proxy
--socks5-gssapi-service NAME SOCKS5 proxy service name for gssapi
--socks5-gssapi-nec Compatibility with NEC SOCKS5 server
-Y, --speed-limit RATE Stop transfers below speed-limit for 'speed-time' secs
-y, --speed-time SECONDS Time for trig speed-limit abort. Defaults to 30
--ssl Try SSL/TLS (FTP, IMAP, POP3, SMTP)
--ssl-reqd Require SSL/TLS (FTP, IMAP, POP3, SMTP)
-2, --sslv2 Use SSLv2 (SSL)
-3, --sslv3 Use SSLv3 (SSL)
--ssl-allow-beast Allow security flaw to improve interop (SSL)
--stderr FILE Where to redirect stderr. - means stdout
--tcp-nodelay Use the TCP_NODELAY option
-t, --telnet-option OPT=VAL Set telnet option
--tftp-blksize VALUE Set TFTP BLKSIZE option (must be >512)
-z, --time-cond TIME Transfer based on a time condition
-1, --tlsv1 Use => TLSv1 (SSL)
--tlsv1.0 Use TLSv1.0 (SSL)
--tlsv1.1 Use TLSv1.1 (SSL)
--tlsv1.2 Use TLSv1.2 (SSL)
--tlsv1.3 Use TLSv1.3 (SSL)
--tls-max VERSION Use TLS up to VERSION (SSL)
--trace FILE Write a debug trace to the given file
--trace-ascii FILE Like --trace but without the hex output
--trace-time Add time stamps to trace/verbose output
--tr-encoding Request compressed transfer encoding (H)
-T, --upload-file FILE Transfer FILE to destination
--url URL URL to work with
-B, --use-ascii Use ASCII/text transfer
-u, --user USER[:PASSWORD] Server user and password
--tlsuser USER TLS username
--tlspassword STRING TLS password
--tlsauthtype STRING TLS authentication type (default SRP)
--unix-socket FILE Connect through this UNIX domain socket
-A, --user-agent STRING User-Agent to send to server (H)
-v, --verbose Make the operation more talkative
-V, --version Show version number and quit
-w, --write-out FORMAT What to output after completion
--xattr Store metadata in extended file attributes
-q If used as the first parameter disables .curlrc
网友评论