作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
您好,我正在尝试使用 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/
我是一名优秀的程序员,十分优秀!