http://qs321.pair.com?node_id=909950

vit has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
I have a web service written in Perl/CGI which I place on different servers including local where I do development.
Production ones have https certified connection for login/registration.
How can I check that https is open automatically in order to place right action URL in the login form (HTTPS://myservice.... instead of a regular one HTTP://.....)?
In other words I want to put a right $action in
<form name="query_form" action=$action method="POST"

Replies are listed 'Best First'.
Re: Check https connection open
by BrowserUk (Patriarch) on Jun 16, 2011 at 15:25 UTC

    Total speculation: couldn't you try opening a port to localhost:443 and decide upon the success or failure of that?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Check https connection open
by Mr. Muskrat (Canon) on Jun 16, 2011 at 15:41 UTC

    Have you tried leaving the scheme off of the URI? Something like '//myservice....'? That's how I've done it before. If you access the page with http, you get http. If you access the page with https, you get https.

Re: Check https connection open
by dorko (Prior) on Jun 16, 2011 at 14:08 UTC
    Hello,

    If I understand your question, you could fetch a known good URL on the server in question using HTTPS. If the HTTPS fetch succeeds, then have the URLs in your program use HTTPS.

    If a HTTPS fetch fails, you can quit the program, or do something else to find out what is going on (like checking HTTP, etc.)

    Cheers,

    Brent

    -- Yeah, I'm a Delt.
Re: Check https connection open
by Anonymous Monk on Jun 16, 2011 at 14:15 UTC
    How can I check that https is open automatically in order to place right action URL in the login form (HTTPS://myservice.... instead of a regular one HTTP://.....)?

    What does "check that https is open automatically" mean?

    If you use relative urls/action, visiting https, remains on https

      I want to use HTTPS in my site url when it is available and HTTP when it is not.
      On our production server we opened a special port in Amazon EC2 for HTTPS secure communication, whereas on my local server I don't have it.
      So I want to form a right action automatically without manually changing to http on my local server and back to https on production server in my code.
      In other words I want to put a right $action in
      <form name="query_form" action=$action method="POST"