android httpclient Host is unresovedエラー解決方案


作者もずっとこの問題に出会って、とても奇怪で、wifiで接続して、問題がなくて、wifiを閉鎖しますかますwifi区域にいないで、私のサーバーを接続することができません.
 
 
読者はまずこの文章を読んでください. http://blog.csdn.net/dropWater_yjqbll/archive/2010/12/16/6079531.aspx
 
接続できない主な原因は私たちの携帯は全部モバイルまたは聯通の代理店を通して出て行くので、直接発送できません.
 
自分でタイプを書きました.
public static String request(int netType, String host, String url,  
            int method, List<NameValuePair> pamrams) {  
        if(netType==HttpUtil.WAP_INT){ //wap    
            HttpRequestBase request = null;  
            String strReust = null;  
            try { //wap  
                //   http://klmu.v228.10000net.cn/publicbicycle   klmu.v228.10000net.cn  
                HttpHost target = new HttpHost(getHostStr(host),Integer.parseInt(getPort(host)));  
                if (method == 0) {  
                    request = new HttpPost(getUrl(host,url));  
                    if (pamrams != null) {  
                        ((HttpPost) request).setEntity(new UrlEncodedFormEntity(  
                                pamrams, HTTP.UTF_8));  
                    }  
                } else if (method == 1) {  
                    request = new HttpGet(url);  
                }  
                //  HttpClient     
                DefaultHttpClient httpClient = new DefaultHttpClient();  
                HttpHost proxy = new HttpHost("10.0.0.172", 80);  
                httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,  
                        proxy);  
                HttpResponse httpResponse = httpClient.execute(target, request);  
                if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {  
                    strReust = EntityUtils.toString(httpResponse.getEntity());  
                } else {  
                    strReust = HTTPERROR_Start + "    httpCode: "+ httpResponse.getStatusLine().getStatusCode() + HTTPERROR_END;  
                }  
                httpClient.getConnectionManager().shutdown();  
            } catch (Exception e) {  
                strReust = HTTPERROR_Start + e.getMessage() + HTTPERROR_END;  
            }  
            return strReust;  
        } else if(netType==HttpUtil.WIFI_INT){ //wifi  
            url = host+url;  
            HttpRequestBase request = null;  
            String strReust = null;  
            try {  
                if (method == 0) {  
                    request = new HttpPost(url);  
                    if (pamrams != null) {  
                        ((HttpPost) request).setEntity(new UrlEncodedFormEntity(  
                                pamrams, HTTP.UTF_8));  
                    }  
                } else if (method == 1) {  
                    request = new HttpGet(url);  
                }  
                //                     
//              HttpParams httpParams = new BasicHttpParams();  
//              HttpConnectionParams.setConnectionTimeout(httpParams, 500);  
//              HttpConnectionParams.setSoTimeout(httpParams, 60 * 1000);  
                //  HttpClient     
                //HttpClient httpClient = new DefaultHttpClient(httpParams);  
                HttpClient httpClient = new DefaultHttpClient();  
                HttpResponse httpResponse = httpClient.execute(request);  
                if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {  
                    strReust = EntityUtils.toString(httpResponse.getEntity());  
                } else {  
                    strReust = HTTPERROR_Start + "    httpCode: "+ httpResponse.getStatusLine().getStatusCode()+ HTTPERROR_END;  
                }  
                httpClient.getConnectionManager().shutdown();  
            } catch (Exception e) {  
                strReust = HTTPERROR_Start + e.getMessage() + HTTPERROR_END;  
            }  
            return strReust;  
        } else {  
            return  HTTPERROR_Start + "      !" + HTTPERROR_END;  
        }  
    }  
 
*
* 1:wifi  
* 2:wap  
* 3:        
* @since May 10, 2011  
* @param conn  
* @return <Description>  
*  
*/  
ublic static int getNetType(Context ctx) {  
ConnectivityManager conn = (ConnectivityManager)ctx.getSystemService(Context.CONNECTIVITY_SERVICE);  
if (conn == null){  
    return HttpUtil.NONET_INT;  
}  
NetworkInfo info = conn.getActiveNetworkInfo();  
if (info == null){  
    return HttpUtil.NONET_INT;  
}  
String type = info.getTypeName();//MOBILE(GPRS);WIFI  
Log.v("tag", "NetworkType=" + type);  
if (type.equals("WIFI")) {  
    return HttpUtil.WIFI_INT;  
} else {//if (type.equals("MOBILE")) {  
    return HttpUtil.WAP_INT;  
}  
 
私はモバイルカードを使っていますので、HttpHost proxy=new HttpHost(「10.0.0.172」、80)これは書き終わりました.ここではアプリの中のデータを取るべきです.移動と聯通は同じです.全部この代理住所です.