我有一个脚本,它充当curl
的 Package 器:它接受curl的所有参数,但也添加一些自己的参数(如-H 'Content-Type: application/json'
),然后对输出进行一些解析。
问题是curl接受curl google.com
作为curl http://google.com
的含义。我想强制HTTPS连接,但我不想解析curl的命令行来查找和编辑主机名。(用户可能输入了curlwrapper -H "foo: bar" -XPOST google.com -d '{"hello":"world"}'
)
有没有什么方法可以告诉curl“在没有提供URL方案的情况下使用HTTPS连接”?
2条答案
按热度按时间4si2a6ki1#
这似乎是不可能的,因为libcurl在没有给出方案的情况下如何确定要使用的协议。
lf3rwulv2#
可以使用选项设置缺少方案部分的URL的HTTPS协议(从而也绕过@FatalError的(过时)答案中提到的协议猜测)
--proto-default https
自2015年10月发布的7.45.0版本起。另请参阅https://github.com/curl/curl/pull/351。
可以将其放入~/. curlrc中。
示例:
第一个
(Note这并不是一个确保安全的神奇选项。例如,根据手册,如果设置了HTTP代理,它不会影响HTTP代理。)