Anroid使用DefaultHttpClient访问Wap网络
2009-06-29 16:34 cppguy 阅读(5812) 评论(1) 编辑 收藏 举报
访问中国移动的Wap网络需要设置代理: Host:"10.0.0.172" Port:80
在Android中,有两种不同的HttpClient类,一个是Java.net包中的:HttpURLConnection,它设置代理代码如下:
Proxy proxy=new Proxy(java.net.Proxy.Type.HTTP,new InetSocketAddress("10.0.0.172",80));
HttpURLConnection connection=(HttpURLConnection) url.openConnection(proxy);
还有一个是Apache的HttpClient:
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpHost proxy = new HttpHost("10.0.0.172", 80);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
在Android中,有两种不同的HttpClient类,一个是Java.net包中的:HttpURLConnection,它设置代理代码如下:
Proxy proxy=new Proxy(java.net.Proxy.Type.HTTP,new InetSocketAddress("10.0.0.172",80));
HttpURLConnection connection=(HttpURLConnection) url.openConnection(proxy);
还有一个是Apache的HttpClient:
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpHost proxy = new HttpHost("10.0.0.172", 80);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);