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

最佳答案

由于 libcurl 在没有给出方案时如何确定要使用的协议(protocol),这似乎是不可能的。 the code 的摘录:

  /*
   * 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";
  }

关于bash - curl 可以默认使用 https 吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31479263/

10-12 07:35
查看更多