您的位置:首页 > 移动开发 > Android开发

Android 设置wap请求方式

2012-04-03 11:36 351 查看
/*
* 发送获取手机号码的请求
* */
public static String sendPhoneNumRequest(String imsi,Context context)throws Exception {
String result = "";
String urlStr = "http://xxxxxxxxxxxxxxxx";

Proxy proxy = new Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress("10.0.0.200",80));//电信CTWAP代理地址是10.0.0.200
URL url = new URL(urlStr);
HttpURLConnection conn=(HttpURLConnection) url.openConnection(proxy);

if (conn == null){
throw new IOException("URLConnection instance is null");
}

conn.setConnectTimeout(30000);//
conn.setDoOutput(true); // 发送POST请求必须设置允许输出,表示允许对外输出
conn.setUseCaches(false); // 不使用Cache
conn.setRequestMethod("GET");

conn.setRequestProperty("Accept", "*/*");
conn.setRequestProperty("Connection", "Keep-Alive");// 维持长连接
conn.setRequestProperty("Charset", "UTF-8");
conn.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");

int responseCode = conn.getResponseCode();
Log.i("IndexActivity","responseCode is:"+responseCode);
if(responseCode == 200){
InputStream stream = conn.getInputStream();
result = inStream2String(stream);
}else{

}

return result;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: