curl 使用示例 详细

本文详细介绍了curl命令的各种用法,包括获取和发送文件、代理设置、FTP上传下载、续传、多进程分块下载等高级技巧,并展示了如何设置HTTP头部、Cookies、User-Agent等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

NAME
curl - transfer a URL

SYNOPSIS
curl [options] [URL...]

DESCRIPTION
curl is a client to get documents/files from or send documents to a server,
using any of the supported protocols (HTTP, HTTPS, FTP, GOPHER, DICT, TELNET, LDAP or FILE).
The command is designed to work without user interaction or any kind of interactivity.
curl offers a busload of useful tricks like proxy support, user authentication, ftp upload,
HTTP post, SSL (https:) connections,cookies, file transfer resume and more.

URL
The URL syntax is protocol dependent. You'll find a detailed description in RFC 2396.


查看响应头
curl -I http://www.bbc.com

保存到文件
curl -o filename http://www.bbc.com

绑定ip测试
curl -X"GET" -H"Host: tools.bbc.com" -O http:/shenfenzheng.htm

从ftp下载
curl -u test:test -O ftp:/a.txt
或curl -O ftp://test:test@*.*.*.*:21/zhuh.txt
    -O Write output to a file named as the remote file

上传至ftp
curl -T ./t.xt ftp://test:test@*.*.*.*:21/

指定referer
curl -e http://www.baidu.com http://www.bbc.com

代理
curl "http://iframe.ip138.com/ic.asp"
curl -x *.*.*.*:3333 "http://iframe.ip138.com/ic.asp"

保存cookie
curl -c ./cookie01 http:/setCookie.php
或curl -D ./dumpheader http:/setCookie.php

发送cookie到服务器
curl -b ./cookie01 http:/showCookie.php

指定UA
curl -v -A "User-AgentMozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20100101 Firefox/16.0"http://8.8.8.8/setCookie.php

续传
curl -C -O http://download.bbc.com/Setup_V2.4.exe

分块多进程下载
curl -r 0-1024000 -o "ie1" http://download.bbc.com/Setup_V2.4.exe &\
curl -r 1024001-2048000 -o "ie2" http://download.bbc.com/Setup_V2.4.exe &\
curl -r 2048001-4096000 -o "ie3" http://download.bbc.com/Setup_V2.4.exe &\
curl -r 4096001- -o "ie4" http://download.bbc.com/setupV2.4.exe &
cat ie* > ie.exe

使用POST方式提交表单
curl -d"cmd=login" -d"password=af8f9dffa5d420fbc2491416962ee" -d"username=testcurl"http://login.bbc.com/login.php

取状态码
curl -o /dev/null -s -w"%{http_code},%{time_total}" http://www.bbc.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值