android客户端使用电信CTWAP网络连接服务器,经常连接不上

BenPeng 发布于 2013/07/16 10:15
阅读 1K+
收藏 0

在android项目里需要对电信CTWAP网络进行适配,遇到连接不了服务器的问题,
在公司这边的广州电信联想A560e机子上连接不了的时候,只要重开一下网络过一会就能连上了,但是在北京客户的三星S4 和酷派手机上怎么也连不上,请问用CTWAP网络发送http请求有什么要注意的吗,还是与服务器端的写法有关?



http请求主要代码:


            HttpURLConnection uRLConnection;

            URL url = new URL(strUrl);

            Proxy proxy = new Proxy(java.net.Proxy.Type.HTTP,                                                    new InetSocketAddress("10.0.0.200", 80));

            uRLConnection = (HttpURLConnection) url.openConnection(proxy);
            uRLConnection.setDoInput(true);
            uRLConnection.setDoOutput(true);
            uRLConnection.setRequestMethod("POST");
            uRLConnection.setUseCaches(false);
            uRLConnection.setInstanceFollowRedirects(false);
            uRLConnection.setRequestProperty("Content-Type", "application/json");
            uRLConnection.setConnectTimeout(20000);
            uRLConnection.connect();

            DataOutputStream out = new DataOutputStream(uRLConnection.getOutputStream());
            if (strParams != null)
               out.write(strParams.toString().getBytes("UTF-8"));
            if (dataOutput != null) {
               out.write(dataOutput, 0, dataOutput.length);
            }
           out.flush();
           out.close();

           InputStream stream = uRLConnection.getInputStream();
           BufferedReader reader = new BufferedReader(new InputStreamReader(
stream, "UTF-8"), 8192);

           StringBuilder builder = new StringBuilder();
           String readLine = null;
           while ((readLine = reader.readLine()) != null) {
             builder.append(readLine);
           }
           stream.close();
           reader.close();
           uRLConnection.disconnect();

报错如下:
libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186)
com.aZaaS.task.GetDataTask.doHttpURLConnectionPost(GetDataTask.java:231)
com.aZaaS.task.GetDataTask.doInBackground(GetDataTask.java:93)
com.aZaaS.task.GetDataTask.doInBackground(GetDataTask.java:1)
android.os.AsyncTask$2.call(AsyncTask.java:287)
java.util.concurrent.FutureTask.run(FutureTask.java:234)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
java.lang.Thread.run(Thread.java:856)





加载中
0
AbbyPisces
AbbyPisces
是的 我也连不上
0
nevans
nevans

ctwap要验证用户名密码,urlconnection我未试过,以下是一段httpclient的写法:

UsernamePasswordCredentials cred = new UsernamePasswordCredentials("ctwap@mycdma.cn", "vnet.mobi");
HttpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, cred);

返回顶部
顶部