IT袋

当前位置:主页 > 经验教程 > 建站编程 >

curl命令怎么用

curl命令怎么用 curl常用命令及参数详解(11)

更新:2023-08-11 17:28:08 来源:IT袋 作者:马勇
导读:curl命令怎么用,echo user = user:passwd | curl -K - http://that.secret.site.com Extra Headers When using curl in your own programs, you may end up needing to pass on your own custom headers when getting a web page. Y

curl命令怎么用

echo "user = user:passwd" | curl -K - http://that.secret.site.com
Extra Headers
When using curl in your own programs, you may end up needing to pass on your own custom headers when getting a web page. You can do this by using the -H flag.

Example, send the header X-you-and-me: yes to the server when getting a page:

curl -H "X-you-and-me: yes" www.love.com

如果您希望 curl 在标题中发送与通常不同的文本,这也很有用。然后,-H您指定的标头将替换 curl 通常会发送的标头。如果将内部标头替换为空标头,则会阻止发送该标头。要防止使用Host:标头:

curl -H "Host:" www.server.com

FTP 和路径名称

请注意,在获取带有ftp://URL 的文件时,给定的路径是相对于您输入的目录的。README要从ftp 站点的主目录中获取文件,请执行以下操作:

curl ftp://user:passwd@my.site.com/README

如果您想要来自同一站点根目录的 README 文件,则需要指定绝对文件名:

curl ftp://user:passwd@my.site.com//README

(即文件名前有一个额外的斜杠。)

SFTP 和 SCP 以及路径名称

对于 sftp: 和 scp: URL,给出的路径名是服务器上的绝对名称。要访问与远程用户的主目录相关的文件,请在文件前面加上/~/,例如:

curl -u $USER sftp://home.example.com/~/.bashrc

FTP 和防火墙

FTP 协议要求相关方之一在数据即将传输时立即打开第二个连接。有两种方法可以做到这一点。

curl 的默认方式是发出 PASV命令,该命令导致服务器打开另一个端口并等待客户端执行的另一个连接。如果客户端位于不允许传入连接的防火墙后面,这很好。

curl ftp.download.com

例如,如果服务器位于防火墙后面,不允许在 21 以外的端口上进行连接(或者如果它只是不支持该PASV命令),则另一种方法是使用该PORT命令并指示服务器进行连接在给定的 IP 号和端口上发送给客户端(作为 PORT 命令的参数)。

curl的-P标志支持几个不同的选项。您的机器可能有多个 IP 地址和/或网络接口,curl 允许您选择使用其中的哪一个。也可以使用默认地址:

curl -P - ftp.download.com
PORT使用但使用我们接口的 IP 地址下载le0(这在 Windows 上不起作用):

curl -P le0 ftp.download.com
下载PORT但使用 192.168.0.10 作为我们使用的 IP 地址:

curl -P 192.168.0.10 ftp.download.com

网络接口

Get a web page from a server using a specified port for the interface:

curl --interface eth0:1 http://www.example.com/
or

curl --interface 192.168.1.10 http://www.example.com/
HTTPS
Secure HTTP requires a TLS library to be installed and used when curl is built. If that is done, curl is capable of retrieving and posting documents using the HTTPS protocol.

Example:

相关阅读