Issue
I have a script which acts as a wrapper around curl
: it accepts all of curl's arguments but also adds some of its own (like -H 'Content-Type: application/json'
), and then it does some parsing of the output.
The problem is that curl accepts curl google.com
as meaning curl http://google.com
. I want to force an HTTPS connection, but I don't want to parse curl's command line to find and edit the hostname. (The user might have typed curlwrapper -H "foo: bar" -XPOST google.com -d '{"hello":"world"}'
)
Is there any way to tell curl "use an HTTPS connection when you're not given a URL scheme"?
Solution
HTTPS protocol for URL with missing scheme part (and thus also bypass protocol guessing mentioned in (obsolete) answer by @FatalError) can be set with option
--proto-default https
since version 7.45.0 from October 2015. See also https://github.com/curl/curl/pull/351.
It can be put into ~/.curlrc.
Example:
$ 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
...
(Note that it's not a magic option to assure security. It e.g. won't affect http proxy, if set, according to the manual.)
Answered By - mykhal Answer Checked By - David Goodson (WPSolving Volunteer)