HttpURLConnection移动网络

时间:2017-11-01 16:02:34

标签: android httpurlconnection 3g

使用3g(任何移动网络)时,我无法通过HttpURLConnection连接到Web服务。我不确切地知道这个问题,因为当它在wifi上时,它完美地工作。当我检查errorStream时,它表示缓冲区长度未知。为什么它只通过3g发生?

我的代码是:

        if (method_type == 0) {
            param = url[0].concat("?identificacao=" + postDataParam.get("identificacao") + "&senha=" + postDataParam.get("senha"));
            System.out.println(param);
            try{
                URL link = new URL(param);
                HttpURLConnection e = (HttpURLConnection)link.openConnection();
                e.setReadTimeout(15000);
                e.setConnectTimeout(15000);
                e.setRequestMethod("GET");
                e.setRequestProperty("User-Agent", "");
                e.setRequestProperty("Authorization", "Basic " + base64CredenciaisCodificadas);
                BufferedReader in = new BufferedReader(
                        new InputStreamReader(e.getInputStream()));
                String inputLine;
                StringBuffer response = new StringBuffer();

                while ((inputLine = in.readLine()) != null) {
                    response.append(inputLine);
                }
                in.close();

                resposta = response.toString();

                globalResposta = resposta;

                senhaCorreta = Boolean.parseBoolean(separarDados(globalResposta, 0).replace("\"", ""));

            } catch(Exception e){

            }
        }

在你们问之前,我尝试将 User-Agent 更改为Mozilla,AppleWebKit和这些东西。我还设置了在清单上访问互联网的权限。

0 个答案:

没有答案