Android网络开发之返回码302

URL url = new URL("https://www.baidu.com");//这里
                    connection = (HttpURLConnection) url.openConnection();
                    if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
                        Log.e("NETERROR:","not ok"+connection.getResponseMessage()+connection.getResponseCode());
                       return;
                    }
现在网站的传输协议有的是HTTP,有的是HTTPS,当url输入出错时会返回302重定向,修改一下就好

你可能感兴趣的:(Android)