在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();
是的我也连不上
ctwap要验证用户名密码,urlconnection我未试过,以下是一段httpclient的写法:
UsernamePasswordCredentialscred=newUsernamePasswordCredentials("ctwap@mycdma.cn","vnet.mobi");
HttpClient.getCredentialsProvider().setCredentials(AuthScope.ANY,cred);
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。