背景
linux上发起http请求
使用方法
# get请求
curl "http://jwen.me/" # 获取返回的信息头 curl -i "http://jwen.me/" # post请求 curl -X POST -d "name=jwen&age=29" "http://jwen.me/" # 自定义header curl -H "Accept-Language: en-US" "http://jwen.me/" # 采用压缩方式接收返回数据 curl --compressed "https://www.cmcm.com/app-ads.txt"
官方说明:
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-status Verify the status of the server certificate (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 Read config from FILE --connect-timeout SECONDS Maximum time allowed for connection --connect-to HOST1:PORT1:HOST2:PORT2 Connect to host (network level) -C, --continue-at OFFSET Resumed transfer OFFSET -b, --cookie STRING/FILE Read cookies from STRING/FILE (H) -c, --cookie-jar FILE Write cookies to 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-raw DATA HTTP POST data, '@' allowed (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) --dns-servers DNS server addrs to use: 1.1.1.1;2.2.2.2 --dns-interface Interface to use for DNS requests --dns-ipv4-addr IPv4 address to use for DNS requests, dot notation --dns-ipv6-addr IPv6 address to use for DNS requests, dot notation -D, --dump-header FILE Write the received headers to FILE --egd-file FILE EGD socket path for random data (SSL) --engine ENGINE Crypto engine (use "--engine list" for list) (SSL) --expect100-timeout SECONDS How long to wait for 100-continue (H) -f, --fail Fail silently (no output at all) on HTTP errors (H) --fail-early Fail on first transfer error, do not continue --false-start Enable TLS False Start. -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 Pass custom header LINE 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) --http1.1 Use HTTP 1.1 (H) --http2 Use HTTP 2 (H) --http2-prior-knowledge Use HTTP 2 without HTTP/1.1 Upgrade (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 Use network INTERFACE (or address) -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 Wait SECONDS 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 security LEVEL (F) --libcurl FILE Dump libcurl equivalent code of this command line --limit-rate RATE Limit transfer speed to RATE -l, --list-only List only mode (F/POP3) --local-port RANGE Force use of RANGE for local port numbers -L, --location Follow redirects (H) --location-trusted Like '--location', and send auth to other hosts (H) --login-options OPTIONS Server login options (IMAP, POP3, SMTP) -M, --manual Display the full manual --mail-from FROM Mail from this address (SMTP) --mail-rcpt TO Mail to this/these addresses (SMTP) --mail-auth AUTH Originator address of the original email (SMTP) --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 (SPNEGO) authentication (H) -n, --netrc Must read .netrc for user name and password --netrc-optional Use either .netrc or URL; overrides -n --netrc-file FILE Specify FILE for netrc -:, --next Allows the following URL to use a separate set of options --no-alpn Disable the ALPN TLS extension (H) -N, --no-buffer Disable buffering of the output stream --no-keepalive Disable keepalive use on the connection --no-npn Disable the NPN TLS extension (H) --no-sessionid Disable SSL session-ID reusing (SSL) --noproxy List of hosts which do not use proxy --ntlm Use HTTP NTLM authentication (H) --ntlm-wb Use HTTP NTLM authentication with winbind (H) --oauth2-bearer TOKEN OAuth 2 Bearer Token (IMAP, POP3, SMTP) -o, --output FILE Write to FILE instead of stdout --pass PASS Pass phrase