`
kanpiaoxue
  • 浏览: 1753809 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

curl的基本用法

 
阅读更多

 

官网: https://curl.haxx.se/

官网文档: 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

 

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命令详解(生成方法)

    如果你需要访问指定的URL地址,只需要使用基本语法curl [options] [URL]即可。Curl还提供了许多选项和参数,以满足不同场景下的需求。例如,如果你需要将输出保存到指定文件中,可以使用o [file]选项,或者使用O选项...

    Linux-curl 命令用法大总结.docx

    1、基本用法 2、保存访问的网页 3、测试网页返回值 4、指定proxy服务器以及其端口 5、cookie 6、模仿浏览器 7、伪造referer(盗链) 8、***下载文件 9、断点续传 10、***上传文件 11、显示抓取错误

    curl命令详解.pdf

    在代理上使用基本身份验证 --proxy-digest 在代理上使用数字身份验证 --proxy-ntlm 在代理上使用ntlm 身份验证 -P/--ftp-port &lt;address&gt; 使用端口地址,而不是使用PASV -Q/--quote &lt;cmd&gt; 文件传输前,...

    使用VC6编译-Curl和LibCurl+ssl+ssh2+zlib

    使用VC6编译-Curl和LibCurl+ssl+ssh2+zlib libcurl是一个跨平台的开源网络协议库,支持http, https, rtsp等多种协议 。libcurl同样支持HTTPS证书授权,HTTP POST, HTTP PUT, FTP 上传, HTTP基本表单上传,代理,...

    超全的curl命令详解文档集.zip

     - anyauth 可以使用“任何”身份验证方法  -b/--cookie &lt;name=string/file&gt; cookie字符串或文件读取位置  - basic 使用HTTP基本验证  -B/--use-ascii 使用ASCII /文本传输  -c/--cookie-jar &lt;file&gt; 操作...

    curl:PHP的基本CURL包装器

    卷曲PHP的基本CURL包装器(有关PHP的libcurl扩展的更多信息,请参见 )安装点击上方的download链接或git clone git://github.com/shuber/curl.git用法初始化只需要求并初始化Curl类,如下所示: require_once 'curl....

    curl介绍和基本用法

    curl是一个广泛使用的用来上传和下载的命令行工具,当然严格来讲,它还可以有别的用途。对于测试来讲,它是Web相关测试非常实用的工具,包括debugging,使用起来非常方便。而且另一方面,因为它是纯命令行的工具,...

    分布式搜索 elasticsearch 方案研究 - 基础知识

    分布式搜索elasticsearch研究--- curl基本用法 26 分布式搜索elasticsearch编写自定义分词插件 28 分布式搜索elasticsearch分布式架构 35 分布式搜索elasticsearchParent-Child特性使用 38 分布式搜索elasticsearch...

    php curl基本操作详解

    cURL是与各种的服务器使用各种类型的协议进行连接和通讯的工具。...使用cURL的基本方法如下:首先修改php.ini文件的设置,找到php_curl.dll,取消下在的注释extension=php_curl.dll,因为php默认是不开

    Linux下网络检测与通讯命令netcat、curl的Windows/DOS版

    Linux下网络检测与通讯命令netcat、curl的Windows/DOS版,经过多方努力才攒成的。...但Windows下只自带ping命令,好容易才找到另两个命令的Windows版本,虽然不是最新的,但基本用法一致,希望对大家有用。

    命令行工具curl的常用命令汇总.doc

    Curl支持各种请求方法,包括GET、POST、PUT、DELETE等。它还支持设置请求头、发送表单数据、上传文件、自动跟随重定向、跳过SSL证书验证等功能。Curl的语法简单易懂,可以快速学习和上手。由于Curl是开源的,因此...

    curl:PHP 的基本 CURL 包装器

    PHP 的基本 CURL 包装器(有关 PHP 的 libcurl 扩展的更多信息,请参见 ) 安装 该库可通过 { " require " : { " alioygur/curl " : " ~1.0 " } } 用法 简单的使用示例 简单地初始化和使用Curl类,如下所示: &...

    多卷曲:使用cURL库发出单个或异步请求的简单HTTP客户端

    多网址 一个简单的HTTP客户端,可以使用cURL库发出单个或异步...可以设置基本URL,以便将来与请求相关的方法不必指定完整的端点。 例如: use Bayfront\MultiCurl\Client; $client = new Client('https://jsonplacehol

    CurlHTTP访问模块,Curl深度封装,重写异步高并发框架

    基本框架全部重写,普通的同步访问都没啥大的区别,主要是异步高并发这次大改,个人觉得效率非常不错,但是记住异步访问的一些获取方法,如取响应数据,取响应Cookie,取协议头等,只能在&lt;异步完成&gt;的接受事件里使用...

    human_curl:cURL库的简单包装器

    欢迎来到human_curl的文档! 向人类发出卷曲请求human_curl允许... 调试请求和响应头.netrc支持用法简单获取请求&gt;&gt;&gt; import human_curl as requests # python-requests.org compatibile&gt;&gt;&gt; # import human_curl as hur

    php使用curl伪造浏览器访问操作示例

    本文实例讲述了php使用curl伪造浏览器访问操作。分享给大家供大家参考,具体如下: 原理 服务器主要通过User-Agent识别客户端是何种设备 User-Agent是Http协议中的一部分,属于头域的组成部分。基本格式为: 浏览器...

    PHP中使用cURL实现Get和Post请求的方法

    1.cURL介绍  cURL 是一个利用URL语法规定来传输文件和数据的工具,支持很多协议,如HTTP、FTP、TELNET等。最爽的是,PHP也支持 cURL 库。本文将介绍 cURL 的一些高级特性,以及在PHP中如何运用它。 2.基本结构  ...

    rest-curlclient-php:使用cURL的基本REST客户端

    使用cURL的基本REST客户端 支持PUT,GET,POST,DELETE并使用cURL的简单实现。 基于rest-client-php ,感谢他的工作。 它是为像我这样的人制作的,在某些情况下无法使用pecl_http。 支持GET,POST,PUT,DELETE ...

    php使用curl简单抓取远程url的方法

    本文实例讲述了php使用curl抓取远程url的方法。分享给大家供大家参考。具体如下: cURL是一个非常有用的php库,可以用来连接不通类型的服务器和协议,下面是一个最基本的范例用来抓取远程网页 &lt;?php $c = curl_...

Global site tag (gtag.js) - Google Analytics