gpt4 book ai didi

linux - 如何让curl使用指定的ip而不是在/etc/hosts中设置?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:48:16 32 4
gpt4 key购买 nike

您好,我正在尝试使用 curl 向指定的 ip 地址发送请求,因为如果我在 /etc/hosts 中设置它,它不会立即工作。那么有没有办法在 curl 命令中做到这一点?谢谢。

最佳答案

是的。curl 的作者 Daniel 的新书中有一个例子。

http://ec.haxx.se/usingcurl-connections.html => 为名称提供自定义 IP

您还可以查看联机帮助页

https://curl.haxx.se/docs/manpage.html

--resolve <host:port:address>

Provide a custom address for a specific host and port pair. Using this, you can make the curl requests(s) use a specified address and prevent the otherwise normally resolved address to be used. Consider it a sort of /etc/hosts alternative provided on the command line. The port number should be the number used for the specific protocol the host will be used for. It means you need several entries if you want to provide address for the same host but different ports.

The provided address set by this option will be used even if -4, --ipv4 or -6, --ipv6 is set to make curl use another IP version.

This option can be used many times to add many host names to resolve.

(Added in 7.21.3)

关于linux - 如何让curl使用指定的ip而不是在/etc/hosts中设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39265265/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com