Linux curl命令使用代理、以及代理种类介绍(附:curl命令详解)

目录

一、代理服务器分类:

二、Linux curl命令代理设置参数:

三、Linux curl命令设置代理举例:

1、linux curl命令设置http代理:

2、Linux curl命令设置socks代理:

四、测试代理的隐匿度:

1、测试前准备:

2、测试使用不同代理输出结果:

五、附录:

CURL命令详解


有时出于个人隐私的原因,我们希望隐藏自己的IP,让http服务器无法记录我们访问过它,这时我们可以使用代理服务器。
  代理服务器(Proxy Server)是工作在浏览器与http服务器之间的一个服务应用,所有经过代理服务器的http请求,都会被转发到对应的http服务器上。
  当然,除了http可以使用代理外,https、ftp、RTSP、pop3等协议同样可以使用代理访问,不过本文介绍的是支持http、https协议访问的代理。

一、代理服务器分类:

  我们比较常用、支持http(s)协议代理主要分为两大类:http代理socks代理,见下表:

大类小类子类描述
http代理http代理
https代理
透明代理http服务器知道浏览器端使用了代理,并能获取浏览器端原始IP;
匿名代理http服务器知道浏览器端使用了代理,但无法获取浏览器端原始IP;
高匿名代理http服务器不知道浏览器端使用了代理,且无法获取浏览器端原始IP;
SOCKS代理SOCKS4被称为全能代
理,支持http
和其他协议
只支持TCP应用;
SOCKS4A支持TCP应用;支持服务器端域名解析;
SOCKS5支持TCP和UDP应用;支持服务器端域名解析;
支持多种身份验证;支持IPV6;

 

二、Linux curl命令代理设置参数:

  linux curl命令可以使用下面参数设置http(s)代理、socks代理,已经设置它们的用户名、密码以及认证方式:

参数用法
-x host:port
-x [protocol://[user:pwd@]host[:port]
--proxy [protocol://[user:pwd@]host[:port]
使用HTTP代理访问;如果未指定端口,默认使用8080端口;
protocol默认为http_proxy,其他可能的值包括:
http_proxy、HTTPS_PROXY、socks4、socks4a、socks5;
如:
--proxy 8.8.8.8:8080;
-x "http_proxy://aiezu:123@aiezu.com:80"
--socks4 <host[:port]>
--socks4a <host[:port]>
--socks5 <host[:port]>
使用SOCKS4代理;
使用SOCKS4A代理;
使用SOCKS5代理;
此参数会覆盖“-x”参数;
--proxy-anyauth
--proxy-basic
--proxy-diges
--proxy-negotiate
--proxy-ntlm
代理认证方式,参考:
--anyauth
--basic
--diges
--negotiate
--ntlm
-U <user:password>
--proxy-user <user:password>
设置代理的用户名和密码;


 

三、Linux curl命令设置代理举例:

1、linux curl命令设置http代理:

# 指定http代理IP和端口
curl -x 113.185.19.192:80 http://aiezu.com/test.php
curl --proxy 113.185.19.192:80 http://aiezu.com/test.php
 
#指定为http代理
curl -x http_proxy://113.185.19.192:80 http://aiezu.com/test.php
 
#指定为https代理
curl -x HTTPS_PROXY://113.185.19.192:80 http://aiezu.com/test.php
 
#指定代理用户名和密码,basic认证方式
curl -x aiezu:123456@113.185.19.192:80 http://aiezu.com/test.php
curl -x 113.185.19.192:80 -U aiezu:123456 http://aiezu.com/test.php
curl -x 113.185.19.192:80 --proxy-user aiezu:123456 http://aiezu.com/test.php
 
#指定代理用户名和密码,ntlm认证方式
curl -x 113.185.19.192:80 -U aiezu:123456 --proxy-ntlm http://aiezu.com/test.php
 
#指定代理协议、用户名和密码,basic认证方式
curl -x http_proxy://aiezu:123456@113.185.19.192:80 http://aiezu.com/test.php

2、Linux curl命令设置socks代理:

#使用socks4代理,无需认证方式
curl --socks4 122.192.32.76:7280 http://aiezu.com/test.php
curl -x socks4://122.192.32.76:7280 http://aiezu.com/test.php
 
#使用socks4a代理,无需认证方式
curl --socks4a 122.192.32.76:7280 http://aiezu.com/test.php
curl -x socks4a://122.192.32.76:7280 http://aiezu.com/test.php
 
#使用socks5代理,basic认证方式
curl --socks5 122.192.32.76:7280 -U aiezu:123456 http://aiezu.com/test.php
curl -x socks5://aiezu:123456@122.192.32.76:7280 http://aiezu.com/test.php
 
#使用socks5代理,basic认证方式,ntlm认证方式
curl -x socks5://aiezu:123456@122.192.32.76:7280 --proxy-ntlm http://aiezu.com/test.php

四、测试代理的隐匿度:

1、测试前准备:

  测试前,我们先在网站根目录也一个php页面“test.php”,用于输出http服务器接收到的访客IP地址信息,"test.php"测试页的代码如下:

<?php
$array = array('HTTP_USER_AGENT', 'HTTP_HOST', 'HTTP_ACCEPT', 'PATH', 'SERVER_SIGNATURE', 'SERVER_SOFTWARE', 'SERVER_NAME', 'SERVER_ADDR', 'SERVER_PORT', 'DOCUMENT_ROOT', 'SERVER_ADMIN', 'SCRIPT_FILENAME', 'REMOTE_PORT', 'GATEWAY_INTERFACE', 'SERVER_PROTOCOL', 'REQUEST_METHOD', 'QUERY_STRING', 'REQUEST_URI', 'SCRIPT_NAME', 'PHP_SELF', 'REQUEST_TIME');
//  将 $_SERVER 数组赋予 $srv数组;
$srv = $_SERVER;
// 释放掉 $srv中不相关的键
foreach($array as $name ) {
    unset($srv[ $name ]);
}
print_r($srv);

保存好"test.php"后,然后我们通过不用代理,和使用透明代理、匿名代理、高匿名代理、SOCKS分别去访问,看页面输出的内容结果。
  

2、测试使用不同代理输出结果:

  ①.  通过linux curl不使用代理访问:

[root@aiezu.com ~]# curl http://aiezu.com/test.php
Array
(
    [REMOTE_ADDR] => 114.112.104.126
)

可以看出,http服务器获取到的"REMOTE_ADDR"IP地址为"114.112.104.126",此IP地址就是客户端lcurl的真实IP地址。 
 
  ②. 通过linux curl命令使用http透明代理访问:

[root@aiezu.com ~]# curl -x 37.139.9.11:80 http://aiezu.com/test.php
Array
(
    [HTTP_VIA] => 1.1 ThunderVPN (squid/3.3.8)
    [HTTP_X_FORWARDED_FOR] => 114.112.104.126
    [HTTP_CACHE_CONTROL] => max-age=259200
    [HTTP_CONNECTION] => keep-alive
    [REMOTE_ADDR] => 37.139.9.11
)

可以看出REMOTE_ADDR字段变成了代理服务器的IP地址,同时真实IP地址也能从HTTP_X_FORWARDED_FOR字段获取到,还多了一个“HTTP_VIA”字段,可以看出出代理并不能隐藏真实IP,而且也会让http服务器自动浏览器端使用了代理。
 
  ③. 通过linux curl命令使用http匿名代理访问:

[root@aiezu.com ~]# curl -x 60.21.209.114:8080 http://aiezu.com/test.php
Array
(
    [HTTP_PROXY_CONNECTION] => Keep-Alive
    [REMOTE_ADDR] => 60.21.209.114
)

从上面可以看出,REMOTE_ADDR字段变成了代理服务器的IP地址,而且在响应不包含原来的真实IP地址,但是多了HTTP_PROXY_CONNECTION,能判断出使用了代理,得出结论此浏览器客户端使用了匿名代理

  ④. 通过linux curl命令使用http高匿名代理访问:

[root@aiezu.com ~]# curl -x 114.232.1.13:8088 http://aiezu.com/test.php
Array
(
    [REMOTE_ADDR] => 114.232.1.13
)

这次我们惊奇的发现,REMOTE_ADDR同样变成了代理的IP地址,同时不留下任何残留证据证明使用了代理,可以得出结论,这就是传说中的高匿名代理
  
  ④. 通过linux curl命令使用socks5代理访问:

[root@aiezu.com ~]# curl --socks5 122.192.32.76:7280 http://aiezu.com/test.php
Array
(
    [REMOTE_ADDR] => 180.96.54.198
)

可以看出此SOCKS5代理也是高匿名代理。
  

五、附录:

感谢原创作者:http://aiezu.com/article/linux_curl_proxy_http_socks.html


CURL命令详解

curl是一个非常实用的、用来与服务器之间传输数据的工具;支持的协议包括 (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP),curl设计为无用户交互下完成工作;

  curl提供了一大堆非常有用的功能,包括代理访问、用户认证、ftp上传下载、HTTP POST、SSL连接、cookie支持、断点续传...。
 
一、curl命令语法:

curl [options] [URL...]

 
二、curl命令参数详解:
  由于linux curl功能十分强大,所以命令参数十分多,下表只是爱E族(aiezu.com)帅选出来的部分参数,更多参数请运行“man curl”命令查看。

参数组参数描述
urlurl需要抓取的一到多个URLs;
多个下面通配符的方式:
  1、http://{www,ftp,mail}.aiezu.com;
  2、http://aiezu.com/images/[001-999].jpg;
  3、http://aiezu.com/images/[1-999].html;
  4、ftp://aiezu.com/file[a-z].txt


-H "name: value"
--header "name: value"
(HTTP)添加一个http header(http请求头);
-H "name:"
--header "name:"
(HTTP)移除一个http header(http请求头);
-A "string"
--user-agent "string"
【参考】
(HTTP)设置Http请求头“User-Agent”,服务器通过“User-Agent”可以判断客户端使用的浏览器名称和操作系统类型,伪造此参数能导致服务器做出错误判断。
也可以使用“-H”, “--header option”设置此选项;
-e <URL>
--referer <URL>
【参考】
(HTTP)设置访问时的来源页面,告诉http服务从哪个页面进入到此页面;
-e "aiezu.com"相当于“-H "Referer: www.qq.com"”;


-I
--head
(HTTP)只输出HTTP-header,不获取内容(HTTP/FTP/FILE)。
用于HTTP服务时,获取页面的http头;
  (如:curl -I http://aiezu.com)
用于FTP/FILE时,将会获取文件大小、最后修改时间;
  (如:curl -I file://test.txt)
-i
--include
(HTTP)输出HTTP头和返回内容;
-D <file>
--dump-header <file>
(HTTP)转储http响应头到指定文件;
cookie-b name=data
--cookie name=data
【参考】
(HTTP)发送cookie数据到HTTP服务器,数据格式为:"NAME1=VALUE1; NAME2=VALUE2";

如果行中没有“=”,将把参数值当作cookie文件名;

这个cookie数据可以是由服务器的http响应头“Set-Cookie:”行发送过来的;
-c filename
--cookie-jar file name
【参考】
(HTTP)完成操作后将服务器返回的cookies保存到指定的文件;
指定参数值为“-”将定向到标准输出“如控制台”;
-j
--junk-session-cookies
(HTTP)告诉curl放弃所有的"session cookies";
相当于重启浏览器;
代理-x host:port
-x [protocol://[user:pwd@]host[:port]
--proxy [protocol://[user:pwd@]host[:port]
【参考】
使用HTTP代理访问;如果未指定端口,默认使用8080端口;
protocol默认为http_proxy,其他可能的值包括:
http_proxy、HTTPS_PROXY、socks4、socks4a、socks5;
如:
--proxy 8.8.8.8:8080;
-x "http_proxy://aiezu:123@aiezu.com:80"
-p
--proxytunnel
将“-x”参数的代理,作为通道的方式去代理非HTTP协议,如ftp;
--socks4 <host[:port]>
--socks4a <host[:port]>
--socks5 <host[:port]>
【参考】
使用SOCKS4代理;
使用SOCKS4A代理;
使用SOCKS5代理;
此参数会覆盖“-x”参数;
--proxy-anyauth
--proxy-basic
--proxy-diges
--proxy-negotiate
--proxy-ntlm
http代理认证方式,参考:
--anyauth
--basic
--diges
--negotiate
--ntlm
-U <user:password>
--proxy-user <user:password>
设置代理的用户名和密码;
数据
传输
-G
--get
【参考】
如果使用了此参数,“-d/”、“--data”、“--data-binary”参数设置的数据,讲附加在url上,以GET的方式请求; 
-d @file
-d "string"
--data "string"
--data-ascii "string"
--data-binary "string"
--data-urlencode "string"
【参考】
(HTTP)使用HTTP POST方式发送“key/value对”数据,相当于浏览器表单属性(method="POST",enctype="application/x-www-form-urlencoded")
  -d,--data:HTTP方式POST数据;
  --data-ascii:HTTP方式POST ascii数据;
  --data-binary:HTTP方式POST二进制数据;
  --data-urlencode:HTTP方式POST数据(进行urlencode);
如果数据以“@”开头,后紧跟一个文件,将post文件内的内容;
-F name=@file
-F name=<file
-F name=content
--form name=content
【参考】
(HTTP)使用HTTP POST方式发送类似“表单字段”的多类型数据,相当于同时设置浏览器表单属性(method="POST",enctype="multipart/form-data"),可以使用此参数上传二进制文件。

如果字段内容以“@”开头,剩下的部分应该是文件名,curl将会上传此文件,如:
curl -F "pic=@pic.jpg" http://aiezu.com;
curl -F "page=@a.html;type=text/html" http://aiezu.com
curl -F "page=@/tmp/a;filename=a.txt" http://aiezu.com

如果字段内容以“<”开头,剩下的部分应该是文件名,curl将从文件中获取作为此字段的值,如:curl -F "text=<text.txt" http://aiezu.com;
--form-string <key=value>(HTTP)类似于“--form”,但是“@”、“<”无特殊含义;
-T file
--upload-file file
通过“put”的方式将文件传输到远程网址;

选项参数只使用字符"-",将通过stdin读入文件内容;
如:
cat test.txt|curl "http://aiezu.com/a.php" -T - 
curl "http://aiezu.com/a.php" -T - <test.txt

此参数也可以使用通配符:
curl -T "{file1,file2}" http://aiezu.com
curl -T "img[1-1000].png" http://aiezu.com
断点
续传
-C <offset>
--continue-at <offset>
断点续转,从文件头的指定位置开始继续下载/上传;
offset续传开始的位置,如果offset值为“-”,curl会自动从文件中识别起始位置开始传输;
-r <range>
--range <range>
(HTTP/FTP/SFTP/FILE) 只传输内容的指定部分:
0-499:最前面500字节;
-500:最后面500字节;
9500-:最前面9500字节;
0-0,-1:最前面和最后面的1字节;
100-199,500-599:两个100字节;



认证
--basic(HTTP)告诉curl使用HTTP Basic authentication(HTTP协议时),这是默认认证方式;
--ntlm(HTTP)使用NTLM身份验证方式,用于HTTP协议;
一般用于IIS使用NTLM的网站;
--digest(HTTP)使用HTTP Digest authentication加密,用于HTTP协议;
配合“-u/--user”选项,防止密码使用明文方式发送;
--negotiate(HTTP)使用GSS-Negotiate authentication方式,用于HTTP协议;
它主要目的是为它的主要目的是为kerberos5认证提供支持支持;
--anyauth(HTTP)告诉curl自动选择合适的身份认证方法,并选用最安全的方式;
-u user:password
--user user:password
使用用户名、密码认证,此参数会覆盖“-n”、“--netrc”和“--netrc-optional”选项;

如果你只提供用户名,curl将要求你输入密码;

如果你使用“SSPI”开启的curl库做“NTLM”认证,可以使用不含用户名密码的“-u:”选项,强制curl使用当前登录的用户名密码进行认证;

此参数相当于设置http头“Authorization:”;
证书-E <证书[:密码]>
--cert <证书[:密码]>
(SSL)指定“PEM”格式的证书文件和证书密码;
--cert-type <type>(SSL)告诉curl所提供证书的类型:PEM、DER、ENG等;
默认为“PEM”;
--cacert <CA证书>(SSL)告诉curl所以指定的CA证书文件,必须是“PEM”格式;
--capath <CA证书路径>(SSL)告诉curl所以指定目录下的CA证书用来验证;
这些证书必须是“PEM”格式;
--crlfile <file>(HTTPS/FTPS)提供一个PEM格式的文件,用于指定被吊销的证书列表;
-k
--insecure
(SSL)设置此选项将允许使用无证书的不安全SSL进行连接和传输。
SSL
其他
--ciphers <list of ciphers>(SSL)指定SSL要使用的加密方式;如:“aes_256_sha_256”;
--engine <name>设置一个OpenSSL加密引擎用于加密操作;
使用“curl --engine list”查看支持的加密引擎列表;
--random-file(SSL)指定包含随机数据的文件路径名;数据是用来为SSL连接产生随机种子为;
--egd-file <file>(SSL)为随机种子生成器EGD(Entropy Gathering Daemon socket)指定的路径名;
-1/--tlsv1
--tlsv1.0
--tlsv1.1
--tlsv1.2
-2/--sslv2
-3/--sslv3
(SSL)使用TLS版本2与远程服务器通讯;
(SSL)使用TLS 1.0版本与远程服务器通讯;
(SSL)使用TLS 1.1版本与远程服务器通讯;
(SSL)使用TLS 1.2版本与远程服务器通讯;
(SSL)使用SSL版本2与远程服务器通讯;
(SSL)使用SSL版本3与远程服务器通讯;
私钥
公钥
--key <key>(SSL/SSH)指定一个私钥文件名;为指定时自动尝试使用下面文件:“~/.ssh/id_rsa”、“~/.ssh/id_dsa”、“./id_rsa'”、 “./id_dsa”;
--key-type <type>(SSL)指定私钥文件类型,支持:DER、PEM、ENG,默认是PEM;
--pass <phrase>(SSL/SSH)指定私钥文件的密码;
--pubkey <key>(SSH)使用指定文件提供的您公钥;
FTP-P
--ftp-port <接口>
(FTP)FTP主动模式时,设置一个地址等待服务器的连接,如:
网卡:eth1
IP:8.8.8.8
主机名:aiezu.com
可以加端口号:eth1:20000-21000;
--crlf(FTP)上传时将换行符(LF)转换为回车换行(CRLF);
--ftp-account [data](FTP)ftp帐号信息;
--ftp-method [method](FTP)可选值:multicwd/nocwd/singlecwd;
--ftp-pasv(FTP)使用使用PASV(被动)/EPSV模式;
--ftp-skip-pasv-ip(FTP)使用PASV的时,跳过指定IP;
--ftp-create-dirs(FTP)上传时自动创建远程目录;
-l
--list-only
(FTP)列出ftp文件列表;
-B
--use-ascii
(FTP/LDAP)使用Ascii传输模式,用于FTP、LDAP;在ftp中相当与使用了“type=A;”模式。
--disable-epsv(FTP)告诉curl在PASV(被动模式)时不要使用EPSV;
--disable-eprt(FTP)告诉curl在主动模式时禁用EPRT和LPRT;
限速--limit-rate <speed>限制curl使用的最大带宽;如果未指定单位,默认单位为“bytes/秒”,你也可以指定单位为“K”、“M”、“G”等单位,如:“--limit-rate 1m”为限制最大使用带宽为“1m字节/秒”;
-y
--speed-time <time>
If a download is slower than speed-limit bytes per second during a speed-time period, the download gets aborted. If speed-time is used, the default speed-limit will be 1 unless set with -Y.
This option controls transfers and thus will not affect slow connects etc. If this is a concern for you, try the --connect-timeout option.
-Y
--speed-limit <speed>
If a download is slower than this given speed (in bytes per second) for speed-time seconds it gets aborted. speed-time is set with -y and is 30 if not set.
其他
选项
-0/--http1.0(HTTP) 强制curl使用HTTP 1.0而不是使用默认的HTTP 1.1;
--interface <name>使用指定的网卡接口访问;
curl --interface eth0 http://aiezu.com
curl --interface 10.0.0.101 http://aiezu.com
-X <command>
--request <command>
(HTTP)指定与服务器通信使用的请求方法,如:GET、PUT、POST、DELETE等,默认GET;
--keepalive-time <seconds>设置keepalive时间
--no-keepalive关闭keepalive功能;
--no-buffer禁用对输出流缓冲;
--buffer启用输出流缓冲;
-L
--location
(HTTP/HTTPS)追随http响应头“Location:”定向到跳转后的页面;
(在http响应码为3XX时使用,如301跳转、302跳转)
--location-trusted(HTTP/HTTPS)同“--location”,但跳转后会发送跳转前的用户名和密码;
--compressed(HTTP)请求对返回内容使用压缩算法进行压缩;curl支持对gzip压缩进行解压;
--connect-timeout <seconds>指定最大连接超时,单位“秒”;
-m seconds
--max-time seconds
限制整个curl操作的最长时间,单位为秒;
-s
--silent
安静模式。不要显示进度表或错误消息;
-#
--progress-bar
显示进度条;
错误
选项
-f
--fail
(HTTP)连接失败时(400以上错误)不返回默认错误页面,而是返回一个curl错误码“22”;
--retry <num>
--retry-delay <seconds>
--retry-max-time <seconds>
失败重试次数;
重试间隔时间;
最大重试时间;
-S
--show-error
安静模式下显示错误信息;
--stderr <file>错误信息保存文件;
输出-o file
--output file
将返回内容输出到文件。
如果是用过通配符获取多个url,可以使用“#”后跟“数字序号”,curl会自动将它替换对应的关键词,如:
  curl "http://aiezu.com/{a,b}.txt" -o "#1.txt";
  将保存为:“a.txt”,“b.txt”;

  curl "http://aiezu.com/{a,b}_[1-3].txt" -o "#1#2.txt";
  将保存为:a1.txt、a2.txt、a3.txt、b1.txt、b2.txt、b3.txt

  如果要根据规则创建保存目录,参考:“--create-dirs”

指定“-”将定向到标准输出“如控制台”; 
-O
--remote-name
将返回内容输出到当前目录下,和url中文件名相同的文件中(不含目录);
--create-dirs与“-o”参数配合使用,创建必要的本地目录层次结构
-w
--write-out format
操作完成后在返回信息尾部追加指定的内容;要追加的内容可以是一个字符串“string”、从文件中获取“@filename”、从标准输入中获取“@-”

格式参数中可以用%{variable_name} 方式使用响应信息的相关变量,如:%{content_type}、%{http_code}、%{local_ip}...,更多变量参考“man curl”获取;

格式参数可以使用“\n”、“\r”、“\t”等转义字符;
调试--trace <file>转储所有传入和传出的数据到文件,包括描述信息;
使用“-”作为文件名将输出发送到标准输出。
--trace-ascii file转储所有传入和传出的数据到文件,包括描述信息,只转储ASCII部分,更容易阅读;
使用“-”作为文件名将输出发送到标准输出。
这个选项会覆盖之前使用的-v、 --verbose、 --trace-ascii选项;
--trace-time转储文件中添加时间信息;
-K
--config <config file>
从配置文件中读取参数,参考:http://curl.haxx.se/docs/
-v
--verbose
显示更详细的信息,调试时使用;
帮助-M
--manual
显示完整的帮助手册;
-h
--help
linux curl用法帮助;

 
三、Linux curl命令退出码:
下面是linux curl命令的错误代码和她们的相应的错误消息,可能会出现在恶劣的环境。

退出码错误描述
1Unsupported protocol. This build of curl has no support for this protocol.
2Failed to initialize.
3URL malformed. The syntax was not correct.
5Couldn't resolve proxy. The given proxy host could not be resolved.
6Couldn't resolve host. The given remote host was not resolved.
7Failed to connect to host.
8FTP weird server reply. The server sent data curl couldn't parse.
9FTP access denied. The server denied login or denied access to the particular resource or directory you wanted to reach. Most often you tried to change to a directory that doesn't exist on the server.
11FTP weird PASS reply. Curl couldn't parse the reply sent to the PASS request.
13FTP weird PASV reply, Curl couldn't parse the reply sent to the PASV request.
14FTP weird 227 format. Curl couldn't parse the 227-line the server sent.
15FTP can't get host. Couldn't resolve the host IP we got in the 227-line.
17FTP couldn't set binary. Couldn't change transfer method to binary.
18Partial file. Only a part of the file was transferred.
19FTP couldn't download/access the given file, the RETR (or similar) command failed.
21FTP quote error. A quote command returned error from the server.
22HTTP page not retrieved. The requested url was not found or returned another error with the HTTP error code being 400 or above. This return code only appears if -f/--fail is used.
23Write error. Curl couldn't write data to a local filesystem or similar.
25FTP couldn't STOR file. The server denied the STOR operation, used for FTP uploading.
26Read error. Various reading problems.
27Out of memory. A memory allocation request failed.
28Operation timeout. The specified time-out period was reached according to the conditions.
30FTP PORT failed. The PORT command failed. Not all FTP servers support the PORT command, try doing a transfer using PASV instead!
31FTP couldn't use REST. The REST command failed. This command is used for resumed FTP transfers.
33HTTP range error. The range "command" didn't work.
34HTTP post error. Internal post-request generation error.
35SSL connect error. The SSL handshaking failed.
36FTP bad download resume. Couldn't continue an earlier aborted download.
37FILE couldn't read file. Failed to open the file. Permissions?
38LDAP cannot bind. LDAP bind operation failed.
39LDAP search failed.
41Function not found. A required LDAP function was not found.
42Aborted by callback. An application told curl to abort the operation.
43Internal error. A function was called with a bad parameter.
45Interface error. A specified outgoing interface could not be used.
47Too many redirects. When following redirects, curl hit the maximum amount.
48Unknown TELNET option specified.
49Malformed telnet option.
51The peer's SSL certificate or SSH MD5 fingerprint was not ok.
52The server didn't reply anything, which here is considered an error.
53SSL crypto engine not found.
54Cannot set SSL crypto engine as default.
55Failed sending network data.
56Failure in receiving network data.
58Problem with the local certificate.
59Couldn't use specified SSL cipher.
60Peer certificate cannot be authenticated with known CA certificates.
61Unrecognized transfer encoding.
62Invalid LDAP URL.
63Maximum file size exceeded.
64Requested FTP SSL level failed.
65Sending the data requires a rewind that failed.
66Failed to initialize SSL Engine.
67The user name, password, or similar was not accepted and curl failed to log in.
68File not found on TFTP server.
69Permission problem on TFTP server.
70Out of disk space on TFTP server.
71Illegal TFTP operation.
72Unknown TFTP transfer ID.
73File already exists (TFTP).
74No such user (TFTP).
75Character conversion failed.
76Character conversion functions required.
77Problem with reading the SSL CA cert (path? access rights?).
78The resource referenced in the URL does not exist.
79An unspecified error occurred during the SSH session.
80Failed to shut down the SSL connection.
82Could not load CRL file, missing or wrong format (added in 7.19.0).
83Issuer check failed (added in 7.19.0).
XXMore error codes will appear here in future releases. The existing ones are meant to never change.

 

  • 1
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: curl是什么? curl是一个命令行工具,用于从URL地址获取数据。它可以用来发送HTTP、HTTPS、FTP等请求,并且可以获取返回的数据。curl是一个非常强大的工具,可以用来测试Web服务器的响应,模拟HTTP请求等。 curl命令的语法 curl命令的语法如下: curl [options] [URL] 其中,options是可选的参数,URL是要请求的地址。 curl常用选项 curl有很多可选参数,下面是一些常用的选项: -d:提交数据,例如:curl -d "name=value" URL。 -G:以GET方式提交数据,例如:curl -G URL。 -H:添加请求头,例如:curl -H "Content-Type: application/json" URL。 -i:显示响应头信息,例如:curl -i URL。 -L:跟随重定向,例如:curl -L URL。 -o:将响应数据写入文件,例如:curl -o file.txt URL。 -X:指定请求方法,例如:curl -X POST URL。 curl命令示例 下面是一些常见的curl命令示例: 获取网页内容:curl URL。 发送GET请求:curl -G URL。 发送POST请求:curl -X POST -d "name=value" URL。 获取响应头信息:curl -i URL。 跟随重定向:curl -L URL。 将响应数据写入文件:curl -o file.txt URL。 总的来说,curl是一个非常强大的命令行工具,可以用来发送各种请求,并且可以获取返回的数据。如果你需要测试Web服务器的响应,或者模拟HTTP请求,那么curl命令是一个非常好的选择。 ### 回答2: Linux curl命令是一个非常强大的命令行工具,用于向服务器发送网络请求,支持多种协议,如HTTP、HTTPS、FTP、SMTP等。它可以下载文件、上传数据、获取服务器响应、处理Cookie等,同时支持各种不同的参数和选项,具有丰富的功能。 curl的基本用法为: ```curl [选项] [URL]``` 其中,选项用于控制curl请求的方式和行为。常用的选项包括: - `-X/--request [请求方法]`:设置请求的方法,如GET、POST、PUT、DELETE等; - `-H/--header [头信息]`:设置请求头信息; - `-d/--data [请求体数据]`:设置请求体数据,常用于POST请求; - `-o/--output [输出文件名]`:将请求结果输出到指定文件; - `-v/--verbose`:显示更详细的调试信息; - `-c/--cookie [cookie文件名]`:设置cookie文件名,用于保持会话状态; - `-b/--cookie-jar [cookie文件名]`:将服务器返回的cookie信息保存到指定文件中。 除了这些常用选项,curl还支持很多其他的选项,可以根据具体需求进行设置。 curl除了基本使用方式外,还有其他常用功能,包括: - 文件下载:使用`-o`选项配合`-O`选项,可以将服务器文件下载到本地,例如`curl -O http://example.com/file.txt`; - 多文件下载:使用`-O`选项加上多个URL,可以同时下载多个文件,例如`curl -O http://example.com/file1.txt -O http://example.com/file2.txt`; - 文件上传:使用`-F`选项加上文件路径,可以将指定文件上传到服务器,例如`curl -F "file=@/path/to/file" http://example.com/upload`; - 认证操作:使用`-u`选项可以设置用户名和密码,实现HTTP基本认证,例如`curl -u username:password http://example.com`; - 代理设置:使用`-x`选项可以设置代理服务器,例如`curl -x http://proxy.example.com http://example.com`; 总之,curl是一款非常强大的命令行工具,在使用时需要熟练掌握各种选项的用法,才能发挥出它的效果。同时,对于curl用法不熟悉的用户,可以通过查看官方文档或其他优秀教程来加深理解,从而更好地使用这个工具。 ### 回答3: curl命令是一个十分有用的Linux命令,它可以通过命令行方式发送HTTP请求,包括GET,POST等请求方法,也支持cookie,用户名密码认证,HTTPS等一系列功能,非常适合对Web服务进行测试和调试。 使用curl发送请求的基本格式为:curl [options] [URL],其中URL为请求的目标资源的URL地址,而options则表示请求时需要设置的配置信息。 以下是常用的curl配置选项: 1. -X (--request): 指示请求方法,常用的方法包括 GET、POST 等。 2. -H (--header): 设置请求头,常见的请求头包括 User-Agent、Content-Type等。 3. -d (--data): 表示要发送的数据,如表单数据、JSON 数据等。 4. -F (--form): 表示要上传的文件,可以上传多个文件。 5. -u (--user): 指定用户名和密码,用于 HTTP 基本认证。 6. -c (--cookie): 表示请求中携带的 Cookie 值。 7. -o (--output): 将响应输出到指定文件中。 8. -L (--location): 当服务端返回重定向响应时,跟随重定向。 9. -k (--insecure): 允许不受信任的 HTTPS 证书。 10. -i (--include): 输出响应头信息。 11. --limit-rate: 限制请求速率,如1K表示每秒发送1KB数据。 12. --compressed: 表示启用压缩,加快数据传输速度。 除了这些常用选项,curl还提供了很多高级用法,例如:支持数据流的管道传输、对FTP服务的支持、HTTP2协议的支持等等。总之,curl命令是一个功能强大的命令行工具,可以给开发者带来很多便利,但同时也需要一定的技术储备和实践经验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值