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 .
一旦我遇到了使用HttpsURLConnection
而不是HttpURLConnection
时解决的相同问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.