curl可以默认使用https吗?

rggaifut  于 2022-11-24  发布在  其他
关注(0)|答案(2)|浏览(143)

我有一个脚本,它充当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连接”?

4si2a6ki

4si2a6ki1#

这似乎是不可能的,因为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";
  }
lf3rwulv

lf3rwulv2#

可以使用选项设置缺少方案部分的URL的HTTPS协议(从而也绕过@FatalError的(过时)答案中提到的协议猜测)
--proto-default https
自2015年10月发布的7.45.0版本起。另请参阅https://github.com/curl/curl/pull/351
可以将其放入~/. curlrc中。
示例:
第一个
(Note这并不是一个确保安全的神奇选项。例如,根据手册,如果设置了HTTP代理,它不会影响HTTP代理。)

相关问题