用户的联网方式大致有 wap net wifi 三种. 使用android包中提供的函数,HttpConnection只能使用net和wifi,wap方式无法访问. 问? 如何让程序可以通过wap访问网络?
解决方案 »
- android快2年了,这个问题大家给个答案吧。。。
- 通过webVIew加载uri打开另外一个程序
- cursor
- android文本框设置默认输入方式为手写!??
- 通过重力感应的加速度值,怎么计算Matrix的旋转值
- 求救--Android的输出模式
- android平台下能否使用一个后台线程来监控另一个独立程序的运行界面和动作
- 用eclipse编写android代码,没有错误,但是运行时程序异常,强制终止,求高手指点
- 百度地图加载不了是什么情况
- androidStudio升级到3.1之后Genarate Signed APK报错
- 在哪里能获得比较多的android的软件或结识做android的软件的人呢?
- android在1.6api的条件下,如何实现多点触屏,高分请教。。。
conn.setRequestProperty("X-Online-Host", host);
}
conn.setRequestProperty("Accept", "text/plain");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Connection", "Close");
conn.setRequestProperty("Content-Length", String.valueOf(data.length));
conn.connect();
private void doPost() throws IOException{
StringBuilder builder = new StringBuilder();
builder.append("http://");
if(bUsingProxy){
builder.append(proxy);
}else{
builder.append(host);
}
if(urlpage != null){
builder.append("/" + urlpage);
}
String desturl = builder.toString();
InputStream stream = null;
HttpURLConnection conn = null;
try{
byte[] data = params.getBytes();
URL url = new URL(desturl);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST"); conn.setConnectTimeout(connectTimeout);
conn.setReadTimeout(readTimeout);
conn.setDoOutput(true);
conn.setUseCaches(false);
if(bUsingProxy){
conn.setRequestProperty("X-Online-Host", host);
}
conn.setRequestProperty("Accept", "text/plain");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Connection", "Close");
conn.setRequestProperty("Content-Length", String.valueOf(data.length));
conn.connect();
OutputStream outputStream = conn.getOutputStream();
outputStream.write(data);
outputStream.flush();
outputStream.close();
int resp_code = conn.getResponseCode();
Map<String, List<String>> headerMap = conn.getHeaderFields();
listener.action(NetworkListener.RESPONSE_CODE, new Integer(resp_code));
if(resp_code == HttpURLConnection.HTTP_OK){
stream = conn.getInputStream();
if(stream != null){
Log.d("cn.cmcc.t", "GETRESPONSE:" + resp_code);
}
if(mCommand != -1)
listener.action(NetworkListener.RECEIVE_STREAM, new Object[]{new Integer(mCommand),stream});
else
listener.action(NetworkListener.RECEIVE_STREAM, stream);
}
} catch (IOException e) {
e.printStackTrace();
listener.action(NetworkListener.REQUEST_TIMEOUT, null);
} finally{
if(stream != null)
stream.close();
if(conn != null)
conn.disconnect();
}
}
额? net方式, 不用做其他设置,就照普通的来,就可以上网的.... 我也很奇怪.
android.net.Proxy.getPort(context);获得端口