linux curl命令

概要

curl命令支持不同网络协议的数据传输(HTTP, FTP, IMAP, POP3, SCP, SFTP, SMTP, TFTP, TELNET, LDAP or FILE),如通过http协议访问某样资源,或者从ftp上下载文件。

它还支持同时下载多个文件,如 curl ftp://ftp.example.com/file[1-20].jpeg

语法

curl [options] [URL...]

选项

flag 解释 示例
-o 指定新文件名 curl -o [file_name] [URL...]
-# 使用“###”作为进度条显示
curl -# -o [file_name] [URL...]
-O 使用原有的文件名保持
curl -O [URL...]
-C 如果之前的下载被打断过,使用该选项可以从断点开始继续下载 curl -C - [URL...](个人理解需要协议支持才行)
–limit-rate 限制下载或上传的速率 curl --limit-rate [value] [URL]
-u 提供认证方式,用户名和密码
curl -u {username}:{password} [FTP_URL]
-T 上传文件到ftp中
curl -u {username}:{password} -T {filename} {FTP_Location}
-x, –proxy 指定代理
curl -x [proxy_name]:[port] [URL...]

使用curl发送http请求

核心参数

参数

示例

解释

-X/--request

 [GET|POST|PUT|DELETE|] 

使用指定的HTTP method 发出指定的request

-H/--header

-H 'content-type: application/json'

设定requestheader

-i/--include 

显示responseheader

-d/--data

‘{

    "uid": "xxx",

    "cityid": 1

}’

设定HTTP body

-v/--verbose

更多的打印信息,如链接的ip、port,tcp设置,header设置,body长度,请求状态等

-u/--user 

XX:XXX

使用者帐密

-b/--cookie

cookie文件路径

有两种方式指定body

  1. 直接写在命令后面
curl -H 'content-type: application/json' -X POST -d '{"name":"shfbjsf"}' http://www.jnshu.com/aaa

     2.写在本地文件中,指定文件路径即可

curl -X POST -H 'content-type: application/json'  -d @/apps/jsonfile.json http://www.jnshu.com/aaa

文献

  1. Curl发送HTTP请求 - 简书
  2. curl command in Linux with Examples - GeeksforGeeks

 

你可能感兴趣的:(操作系统,linux,运维,服务器)