我有一个脚本,它充当curl的包装器:它接受所有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连接”?
发布于 2022-08-16 20:18:48
带有缺失方案部分的URL的HTTPS协议(因此也可以绕过@FatalError(过时的)答案中提到的协议猜测)可以使用选项来设置
--proto-default https
自2015年10月起开始使用7.45.0版本。另见https://github.com/curl/curl/pull/351。
它可以放进~/..curlrc。
示例:
$ curl -v example.org
* Trying XXXXIPv6redacted:80...
* Connected to example.org (XXXXIPv6redacted) port 80 (#0)
> GET / HTTP/1.1
...$ curl --proto-default https -v example.org
* Trying XXXXIPv6redacted:443...
* Connected to example.org (XXXXIPv6redacted) port 443 (#0)
* ALPN: offers h2
...(请注意,确保安全并不是一个神奇的选择。例如,根据手册设置,它不会影响http代理。)
发布于 2015-07-17 16:02:36
这似乎是不可能的,因为当没有给出方案时,libcurl如何确定要使用的协议。摘录自代码
/*
* Since there was no protocol part specified, we guess what protocol it
* is based on the first letters of the server name.
*/
/* Note: if you add a new protocol, please update the list in
* lib/version.c too! */
if(checkprefix("FTP.", conn->host.name))
protop = "ftp";
else if(checkprefix("DICT.", conn->host.name))
protop = "DICT";
else if(checkprefix("LDAP.", conn->host.name))
protop = "LDAP";
else if(checkprefix("IMAP.", conn->host.name))
protop = "IMAP";
else if(checkprefix("SMTP.", conn->host.name))
protop = "smtp";
else if(checkprefix("POP3.", conn->host.name))
protop = "pop3";
else {
protop = "http";
}https://stackoverflow.com/questions/31479263
复制相似问题