HTTPURLConnection Doesn’t Follow Redirect from HTTP to HTTPS

Redirects are followed only if they use the same protocol. (See the followRedirect() method in the source.) There is no way to disable this check. Even though we know it mirrors HTTP, from the HTTP protocol point of view, HTTPS is just some other, completely different, unknown protocol. It would be unsafe to follow the … Read more

Invalid self signed SSL cert – “Subject Alternative Name Missing”

To fix this, you need to supply an extra parameter to openssl when you’re creating the cert, basically -sha256 -extfile v3.ext where v3.ext is a file like so, with %%DOMAIN%% replaced with the same name you use as your Common Name. More info here and over here. Note that typically you’d set the Common Name … Read more

Redirecting from HTTP to HTTPS with PHP

Try something like this (should work for Apache and IIS): if (empty($_SERVER[‘HTTPS’]) || $_SERVER[‘HTTPS’] === “off”) { $location = ‘https://’ . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘REQUEST_URI’]; header(‘HTTP/1.1 301 Moved Permanently’); header(‘Location: ‘ . $location); exit; }

ASP.NET MVC RequireHttps in Production Only

This won’t help if you run Release builds on your development workstation, but conditional compilation could do the job… #if !DEBUG [RequireHttps] //apply to all actions in controller #endif public class SomeController { //… or … #if !DEBUG [RequireHttps] //apply to this action only #endif public ActionResult SomeAction() { } } Update In Visual Basic, … Read more

Determine if ajax call failed due to insecure response or connection refused

There is no way to differentiate it from newest Web Browsers. W3C Specification: The steps below describe what user agents must do for a simple cross-origin request: Apply the make a request steps and observe the request rules below while making the request. If the manual redirect flag is unset and the response has an … Read more