android wap连接网络设置代理

   访问ctwap,cmwap,uniwap等网络设置代理:

    获取host和port:android.net.Proxy.getDefaultHost(),android.net.Proxy.getDefaultPort();android.net.Proxy.getDefaultHost()不为空,则表示连接的网络是wap;此时,最好设置代理。设置方式如下:

 

    1)Java.net包中的:HttpURLConnection,它设置代理代码如下:
          Proxy proxy=new Proxy(java.net.Proxy.Type.HTTP,new InetSocketAddresshost,port));
          HttpURLConnection connection=(HttpURLConnection) url.openConnection(proxy);


   2)Apache的HttpClient:
       DefaultHttpClient httpclient = new DefaultHttpClient(); 
        HttpHost proxy = new HttpHost(host,port); 
        httpclient.execute(proxy, httpost)

你可能感兴趣的:(apache,android,网络,WAP)