Android网络连接Wifi和cmnet及cmwap的问题

某些Wifi连接,有时候出现100-continue的错误,apache http client说什么协议错误,解决办法:

Java代码  

//关闭Expect:100-Continue握手   //100-Continue握手需谨慎使用,因为遇到不支持HTTP/1.1协议的服务器或者代理时会引起问题   httppost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);  

使用cmwap上网,cmwap本质是使用代理上网,用httpclient,很简单,如下:

Java代码  

HttpHost proxy = new HttpHost("10.0.0.172"80);//设置cmwap代理   httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);  

如果检测呢,以下代码可以检测当前移动网络的apn代理情况。

Java代码  

ConnectivityManager connectivity = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);               if (connectivity != null) {                    // 获取网络连接管理的对象                   NetworkInfo info = connectivity.getActiveNetworkInfo();                      if (info != null && info.isConnected()) {                       // 判断当前网络是否已经连接                       if (info.getState() == NetworkInfo.State.CONNECTED) {                           if(info.getTypeName().equals("WIFI")){                                                           else{                                Uri uri = Uri.parse("content://telephony/carriers/preferapn");                               Cursor cr = context.getContentResolver().query(uri, null,nullnullnull);                               while (cr != null && cr.moveToNext()) {                                     // APN id                                     @SuppressWarnings("unused")                                     String id = cr.getString(cr.getColumnIndex("_id"));                                     // APN name                                     @SuppressWarnings("unused")                                     String apn = cr.getString(cr.getColumnIndex("apn"));                                     // do other things...                                     String strProxy = cr.getString(cr.getColumnIndex("proxy"));                                     String strPort = cr.getString(cr.getColumnIndex("port"));                                     if(strProxy != null && !"".equals(strProxy)){                                         Config.host = strProxy;                                         Config.port = Integer.valueOf(strPort);                                     }                                                                     }                           }                        }                   }   

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wypjxw.html