官网文档: https://curl.haxx.se/docs/manpage.html
国内的使用手册: http://man.linuxde.net/curl
使用curl发送GET请求:curl protocol://address:port/url?args
使用curl发送POST请求: curl -d "args" protocol://address:port/url
curl -H "Content-Type:application/json" -X POST -d 'json data' URL
curl -X POST -H "content-type:application/json" -d "{\"id\":1,\"name\":\"hello\"}" URL
HTTP头部信息也可以使用curl来发送,使用-H"头部信息" 传递多个头部信息,例如:
curl -H "Host:man.linuxde.net" -H "accept-language:zh-cn" URL
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 <directory> 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 <name=string/file> Cookie 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 <name=data/name@filename> HTTP POST data url encoded (H)
--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 <eng> Crypto engine to use (SSL). "--engine list" for list
-f/--fail Fail silently (no output at all) on HTTP errors (H)
-F/--form <name=content> Specify HTTP multipart POST data (H)
--form-string <name=string> Specify HTTP multipart POST data (H)
--ftp-account <data> Account data to send when requested by server (F)
--ftp-alternative-to-user <cmd> 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 <address> Use PORT with address instead of PASV (F)
--ftp-skip-pasv-ip Skip the IP address for PASV (F)
--ftp-ssl Try SSL/TLS for ftp transfer (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)
--ftp-ssl-reqd Require SSL/TLS for ftp 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 <num>[-num] Force use of these local port numbers
-L/--location Follow Location: hints (H)
--location-trusted Follow Location: and send auth to other hosts (H)
-M/--manual Display the full manual
--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
--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
-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 Comma-separated 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)
-#/--progress-bar Display transfer progress as a progress bar
-x/--proxy <host[:port]> Use HTTP 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]> Set 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 file transfer (F/SFTP)
--random-file <file> File for reading random data from (SSL)
-r/--range <range> Retrieve only the bytes within a range
--raw Pass HTTP "raw", without any transfer decoding (H)
-e/--referer Referer URL (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
--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-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 Stop transfer if below speed-limit for 'speed-time' secs
-y/--speed-time Time needed to trig speed-limit abort. Defaults to 30
-2/--sslv2 Use SSLv2 (SSL)
-3/--sslv3 Use SSLv3 (SSL)
--stderr <file> Where to redirect stderr. - means stdout
--tcp-nodelay Use the TCP_NODELAY option
-t/--telnet-option <OPT=val> Set telnet option
-z/--time-cond <time> Transfer based on a time condition
-1/--tlsv1 Use TLSv1 (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
-T/--upload-file <file> Transfer <file> to remote site
--url <URL> Set URL to work with
-B/--use-ascii Use ASCII/text transfer
-u/--user <user[:password]> Set server user and password
-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
-q If used as the first parameter disables .curlrc
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 <directory> 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 <name=string/file> Cookie 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 <name=data/name@filename> HTTP POST data url encoded (H)
--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 <eng> Crypto engine to use (SSL). "--engine list" for list
-f/--fail Fail silently (no output at all) on HTTP errors (H)
-F/--form <name=content> Specify HTTP multipart POST data (H)
--form-string <name=string> Specify HTTP multipart POST data (H)
--ftp-account <data> Account data to send when requested by server (F)
--ftp-alternative-to-user <cmd> 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 <address> Use PORT with address instead of PASV (F)
--ftp-skip-pasv-ip Skip the IP address for PASV (F)
--ftp-ssl Try SSL/TLS for ftp transfer (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)
--ftp-ssl-reqd Require SSL/TLS for ftp 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 <num>[-num] Force use of these local port numbers
-L/--location Follow Location: hints (H)
--location-trusted Follow Location: and send auth to other hosts (H)
-M/--manual Display the full manual
--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
--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
-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 Comma-separated 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)
-#/--progress-bar Display transfer progress as a progress bar
-x/--proxy <host[:port]> Use HTTP 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]> Set 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 file transfer (F/SFTP)
--random-file <file> File for reading random data from (SSL)
-r/--range <range> Retrieve only the bytes within a range
--raw Pass HTTP "raw", without any transfer decoding (H)
-e/--referer Referer URL (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
--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-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 Stop transfer if below speed-limit for 'speed-time' secs
-y/--speed-time Time needed to trig speed-limit abort. Defaults to 30
-2/--sslv2 Use SSLv2 (SSL)
-3/--sslv3 Use SSLv3 (SSL)
--stderr <file> Where to redirect stderr. - means stdout
--tcp-nodelay Use the TCP_NODELAY option
-t/--telnet-option <OPT=val> Set telnet option
-z/--time-cond <time> Transfer based on a time condition
-1/--tlsv1 Use TLSv1 (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
-T/--upload-file <file> Transfer <file> to remote site
--url <URL> Set URL to work with
-B/--use-ascii Use ASCII/text transfer
-u/--user <user[:password]> Set server user and password
-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
-q If used as the first parameter disables .curlrc
python -m SimpleHTTPServer curl http://xxxx:8000/soft/hello.tar.gz -Os
POST请求:
curl -X POST \ http://localhost:8080/api/sayHello \ -H 'Content-Type: application/json' \ -H 'cache-control: no-cache' \ -d '{ "name": "kanpiaoxue", "address": "Beijing" }'
相关推荐
**四、Curl基本用法** Curl命令的基本格式是`curl [选项] URL`。以下是一些常用的选项: - `-L`:跟随重定向。 - `-X` 或 `--request`:指定HTTP请求方法,如`GET`、`POST`等。 - `-d` 或 `--data`:用于POST请求...
**二、curl基本用法** 1. **HTTP方法**:curl支持常见的HTTP方法,如GET、POST、PUT、DELETE等。例如,发送POST请求: ``` curl -X POST -d "key=value" http://example.com/api ``` 2. **URL参数**:在URL后面...
**一、curl 基本用法** 1. **下载文件**:使用 `-O` 或 `--remote-name` 参数,可以将远程URL指定的文件下载到本地,例如 `curl -O http://example.com/file.txt`。 2. **显示HTTP头部**:通过 `-I` 或 `--head` ...
一、curl基本用法 curl的名称来源于"Client URL",其主要功能是通过命令行接口发送HTTP、FTP等网络请求。例如,标题中的`curl http://127.0.0.1:8080/my/resource`命令,就是向本地主机的8080端口发送一个HTTP GET...
但总体而言,文件涵盖了curl命令在Linux环境下的广泛用法,不仅包括基本的文件传输操作,还深入到了网络协议的细节、高级配置选项以及编程接口等方面,是非常全面的curl使用指南。这些知识点对于任何需要使用curl...
2. **CURL库的基本用法**: - 在C++程序中,通过`#include <curl/curl.h>`引入CURL库的头文件。 - 使用`curl_global_init()`初始化CURL库。 - 创建`CURL *curl`对象,代表一个会话。 - 使用`curl_easy_setopt()`...
**curl使用方法及命令介绍** `curl`是一个强大的命令行工具,用于传输数据到或从服务器,支持HTTP、HTTPS、FTP、FTPS等多种协议。它广泛应用于自动化脚本、数据抓取、API交互等场景。以下是对`curl`的一些基本使用...
本文将深入解析PHP下的cURL用法,以便更好地理解和应用。 1. **初始化cURL会话**: 使用`curl_init()`函数来启动一个新的cURL会话。例如: ```php $curl = curl_init(); ``` 2. **设置cURL选项**: `curl_...
首先,我们需要理解`curl`的基本用法。在命令行中,你可以通过指定URL来获取网页内容,如`curl http://example.com`。`curl`还支持许多选项,比如`-L`(跟随重定向)、`-v`(显示详细信息)和`-O`(保存远程文件到...
### Curl的基本用法 1. **下载文件**: 基本的Curl命令格式是`curl [选项] [URL]`。例如,要下载一个网页,你可以输入`curl http://example.com`。默认情况下,Curl会将内容输出到终端。 2. **保存到文件**: 如果你...
1. **CUrlHttp类的基本结构** CUrlHttp类通常会包含一系列的方法,如`init()`用于初始化curl会话,`setOpt()`设置curl选项,`exec()`执行请求,`close()`关闭curl会话。这些方法使得操作更加模块化,易于理解和使用...
封装cURL类的主要目的是将复杂的cURL操作抽象成易于理解和使用的函数或方法,减少代码冗余,提高代码的可读性和可维护性。这样,开发者只需调用类的方法,就能完成网络请求,而无需关心底层的实现细节。 3. **类...
一个基本的 cURL 使用示例如下: ```php $curl = curl_init(); // 初始化 cURL 对象 curl_setopt($curl, CURLOPT_URL, 'http://cocre.com'); // 设置目标URL curl_setopt($curl, CURLOPT_HEADER, 1); // 包含头部...
首先,我们需要理解`curl`的基本用法。在命令行中,`curl`通过指定URL和各种选项来发起网络请求。例如,发送一个GET请求到某个API接口: ```bash curl http://example.com/api ``` 要发送POST数据,我们可以这样做...
标题 "windows 下可以使用curl命令" 暗示了我们讨论的是如何在Windows操作系统环境下使用curl工具。curl是一个强大的命令行工具,用于传输数据到或从服务器,支持多种协议如HTTP、HTTPS、FTP等。在Windows系统中,它...
本手册将详细介绍PHP中cURL的使用方法,包括基本概念、配置选项、常见用法以及实例解析。 ### 1. 安装与配置 在开始使用PHP cURL之前,确保已正确安装并启用cURL扩展。在Linux系统中,通常可以通过运行`php -m`...
首先,我们要了解CURL的基本用法。CURL可以用来发送HTTP请求,获取服务器的响应。例如,使用CURL抓取一个网页的基本命令如下: ```bash curl http://example.com ``` 这会将`http://example.com`的HTML内容打印到...
CURL命令的基本格式为: ```markdown curl -H "Content-Type: application/json" -u username:password -X 请求方法 httpUrl -d '传输数据' ``` 在这个命令中,各部分的含义如下: 1. `-H` 选项用来设置HTTP请求...
### PHP cURL 使用实例详解 #### 一、cURL简介 cURL 是一款强大的命令行工具,用于通过URL从或向服务器传输数据。...cURL 是一个非常强大且灵活的工具,掌握其使用方法对于进行网络编程非常有帮助。
本文将详细介绍`curl`工具在XP系统上的使用方法、功能以及一些常见问题的解决策略。 首先,`curl.exe`是`curl`工具的可执行文件,用户可以在命令行中调用它来执行网络操作。为了在XP系统上使用`curl`,你需要将`...