0

I try to make a GET/POST to http://www.android.com/ like in the example given in the documentation

In the InputStream I get a message saying 302 Moved and tells me to go on https://www.android.com/

When I modify my URL to https, I get:

java.io.FileNotFoundException: https://www.android.com/

HttpsURLConnection con;
String request = "https://www.android.com/";
URL url = new URL(request);
    con = (HttpsURLConnection) url.openConnection();
    con.setDoOutput(true);
    con.setInstanceFollowRedirects(false);
    con.setRequestMethod("GET");
    con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    con.setRequestProperty("charset", "utf-8");
    con.setRequestProperty("Content-Length", Integer.toString(postDataLength));

Update

I thought it was an issue of SSL certificates, but it is not. I've added a function that will blindly trust all SSL certificates. Sources here and here.

BeGreen
  • 765
  • 1
  • 13
  • 39

1 Answers1

2

Once I had the same problem which solved when I used HttpsURLConnection Instead of HttpURLConnection.

AmiNadimi
  • 5,129
  • 3
  • 39
  • 55