I have sent a HTTP GET request to google.com and I get a 302 status. Now the location : url in http header is an
http:// address, instead of https. When the browser visits this address I get back a 302 redirect again but with an https address in the location field of http header. The browser then visits this address and https connection is established. Also the IP of the first server which sent me a 302 redirect is different from the second 302 redirect sender. Finally the server with which I establish an https connection has a different ip.
My question is why do I not get a https redirect in the first 302 reply?
Also, I am using a program which sends an HTML GET request to a server and gets back the response. How can I simulate this chain of 302 redirects to reach the final server which returns an https page?
The program takes as input
./execfile_name host_name page.
Every time I supply the google.com hostname it connects to the same server (same IP). How can I get it to connect to the next server in the chain leading to the final one?