A server is running on 5000 port. I have to write a bash script to cURL that URL and parse the response. Here the problem is server can run on either http or https protocol. That means I have curl either https://serverip:5000 or http://serverip:5000.

For now, first I'm checking with http request. If that request fails then I'm checking https. Is there any way that cURL can automatically detect that server running on http or httpsand request to it?

  • Try --proto =http,https
    – cuonglm
    Feb 1, 2016 at 6:15
  • 1
    Web browsers don't auto-detect https either; they rely on the protocol in the URL.
    – cjm
    Feb 1, 2016 at 6:16
  • @cjm. Yes. But if I browse "google.com", it's going to "https-google.com"
    – gangadhars
    Feb 1, 2016 at 6:31
  • That's because google runs http servers that redirect the request. if you telnet to port 80 of www.google.com and send GET /, you can see the redirect. The browser doesn't do it automatically. Feb 1, 2016 at 7:06
  • @JeffSpaulding Thanks. Got it. edited question.
    – gangadhars
    Feb 1, 2016 at 7:09

1 Answer 1


AFAIK, the "curl" command does not provide a feature for determining if the connection is SSL or not. So you need to use a different tool for checking this.

I've created a small script, which uses "openssl" to determine if the connection specified is SSL or not. Enjoy:


if [ $# -lt 1 ]; then 
    echo "Usage: testssl.sh <host> [port]"
    exit 1;

echo ^d | openssl s_client -connect ${1}:${2:-443} && PROTO="https"
curl ${PROTO}://${1}:${2:-443}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .