我尝试对http://www.android.com/
进行GET / POST,就像在documentation
在InputStream
我收到一条消息302 Moved
并告诉我继续https://www.android.com/
当我将URL
修改为https时,我得到:
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));
更新
答案 0 :(得分:0)
当我使用HttpsURLConnection
代替HttpURLConnection
时遇到了同样的问题。