当前位置:网站首页>curl命令介绍
curl命令介绍
2022-08-10 04:38:00 【叶赫那拉 赫敏】
curl命令介绍
01
简介
curl命令是一个利用URL规则在命令行下工作的文件传输工具。它支持文件的上传和下载,所以是综合传输工具,但按传统,习惯称curl为下载工具。作为一款强力工具,curl支持包括HTTP、HTTPS、ftp等众多协议,还支持POST、cookies、认证、从指定偏移处下载部分文件、用户代理字符串、限速、文件大小、进度条等特征。做网页处理流程和数据检索自动化,curl可以助一臂之力。下面简单介绍下该命令。
02
语法及参数
语法:
curl(选项)(参数)
常用选项:
-a/–append
上传文件时,附加到目标文件
-A/–user-agent <string>
设置用户代理发送给服务器
-b/–cookie <name=string/file>
cookie字符串或文件读取位置
–basic
使用HTTP基本验证
-c/–cookie-jar <file>
操作结束后把cookie写入到这个文件中
-C/–continue-at <offset>
断点续转
-d/–data <data>
HTTP POST方式传送数据
-D/–dump-header <file>
把header信息写入到该文件中
-o/–output
把输出写到该文件中
-O/–remote-name
把输出写到该文件中,保留远程文件的文件名
-R/–remote-time
在本地生成文件时,保留远程文件时间
-u/–user <user[:password]>
设置服务器的用户和密码
-U/–proxy-user <user[:password]>
设置代理用户名和密码
03
示例
1、文件下载及上传
curl可以通过不同的协议下载文件,通过设定特定的命令参数,可以实现灵活的控制下载输出。下面给出几个简单的示例:
- 下载单个文件
curl http://man.linuxde.net/text.iso
- 下载多个文件
curl –o http://man.linuxde.net/text1.iso –o http://man.linuxde.net/text.iso
- 下载文件后输出到指定文件,并显示进度条
curl http://man.linuxde.net/text.iso –o filename.iso –press
- 控制下载速度
curl http://man.linuxde.net/text.iso --limit-rate 50k- 控制下载配额
curl http://man.linuxde.net/text.iso –max-filesize 1000k
- 从ftp下载
curl -u ftpuser:ftppass -O ftp://ftp_server/public_html/xss.php- 断点续传
curl http://man.linuxde.net/text.iso -C 偏移量
#偏移量是以字节为单位的整数,如果让curl自动推断出正确的续传位置使用-C -:curl -C -http://man.linuxde.net/text.iso- 文件上传
curl --form “[email protected]” http://hostname/resource
2、网页流程处理
Curl可以向服务器传输数据,支持常用的http、https、ftp等协议,因此也可以用来对不同请求的正确性和返回数据格式进行验证。下面介绍常用的几个例子:
- 查看网页代码
curl www.so.com
- GET 请求
curl 123-_360搜索 POST 请求
curl -d “userId=28090443&premium=100” "http://www.so.com//addStrategyKeyword
- 显示头信息
curl –i http://www.so.com
- 显示通信过程
curl –v www.so.com
- Cookie使用
curl –cookie “type=xxx” www.so.com
- 增加头信息
curl --header “xxx:xxx” http://www.so.com
- http认证curl –user name:password www.so.com
04
总结
以上只是curl命令的常用方法,其中有不足的地方欢迎大家指正,想了解更详细的用法可以查看这个链接:http://man.linuxde.net/curl
边栏推荐
猜你喜欢
添加路由的2种方式--router
2022G3 Boiler Water Treatment Exam Mock 100 Questions and Mock Exam
2022 R2 transportable pressure vessel filling operation examination question bank simulation platform
线程(中):线程安全
虚假新闻检测论文阅读(七):A temporal ensembling based semi-supervised ConvNet for the detection of fake news
Day14/15/16:哈夫曼树、哈弗曼编码(压缩与解压缩)
长沙:借网红的风,铺长红的路
虚假新闻检测论文阅读(八):Assessing Arabic Weblog Credibility via Deep Co-learning
webrtc学习--websocket服务器
法定代表人和股东是什么关系
随机推荐
qwt库的编译和使用
JS gets the year, month, day, time, etc. of the simple current time
JS获取简单当前时间的年、月、日、时间等
最新开源的面试笔记,天花板级别!
深度学习——循环神经网络RNN 未完待续
Qt编写物联网管理平台50-超强跨平台
众昂矿业:萤石下游需求强劲
【Web3 系列开发教程——创建你的第一个 NFT(7)】创建一个 NFT DApp,给你的 NFT 赋予属性,例如图片
3、ROS工作空间的创建
【论文笔记】Prototypical Contrast Adaptation for Domain Adaptive Semantic Segmentation
BGP实验+选路+路由策略+OSPF
富媒体在客服IM消息通信中的秒发实践
[Web3 Series Development Tutorial - Create Your First NFT (7)] Create an NFT DApp and assign attributes to your NFT, such as pictures
2022 T Elevator Repair Exam Questions and Mock Exams
释放高通量算力价值潜能 JASMINER持续领跑 Web3 市场
[crit] 23856#0: *101796511 stat()
解决“File has been changed outside the editor, reload?”提示
webrtc学习--websocket服务器(二) (web端播放h264)
ZZULIOJ:1019: 公园门票
2022山东省安全员C证考试题及模拟考试