网络权限已设置。隔几分钟出来一次request time failed:java.net.socketException:Address family not surpported by protocol。主要代码贴出来:
                                        String kinds=kindsText.getText().toString();
                                        String area=areaText.getText().toString();
                                        NameValuePair kindsValuePair=new BasicNameValuePair("kinds",kinds);
                                        NameValuePair areaValuePair=new BasicNameValuePair("area",area);
                                        List<NameValuePair> nameValuePairs=new ArrayList<NameValuePair>();
                                        nameValuePairs.add(kindsValuePair);
                                        nameValuePairs.add(areaValuePair);
                                        InputStream inputStream=null;
                                       String baseUrl="http://120.95.137.237:8080/Test/MyJsp.jsp";
                                        HttpPost httpPost=new HttpPost(baseUrl);
                                        try{
                                                HttpEntity requestHttpEntity=new UrlEncodedFormEntity(nameValuePairs,HTTP.UTF_8);
                                                
                                                httpPost.setEntity(requestHttpEntity);
                                                HttpClient httpClient=new DefaultHttpClient();
                                                httpResponse=httpClient.execute(httpPost);
                                                httpEntity=httpResponse.getEntity();
                                                inputStream=httpEntity.getContent();
                                                BufferedReader br=new BufferedReader(new InputStreamReader(inputStream));
                                                String result="";
                                                String line="";
                                                while((line=br.readLine())!=null){
                                                        result=result+line;
                                                }
                                                        System.out.print(result);
                                                
                                        }catch(Exception e){
                                        e.printStackTrace();
                                }

解决方案 »

  1.   

    post请求发送不到servlet上去,android这边的logcat显示:request time failed:java.net.socketException:Address family not supported by protocol.这个问题已经困扰我一个多礼拜了
      

  2.   

    post请求发送不到servlet上去,android这边的logcat每隔几分钟报一次:request time failed:java.net.socketException:Address family not supported by protocol.
      

  3.   

    给你发个专业的http请求吧 /**
     * Role:发送会议ID和Name去服务器验证并取得返回值
     * <BR>Date:2012-2-10
     * <BR>@author CODYY)peijiangping
     */
    public String intermessage(String str1, String str2) {
    //请求路径
    String url = context.getString(R.string.clienturl)+"/TestServlet";
    HttpConnect httpConnect = new HttpConnect(url, context);
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("meetid", str1));
    params.add(new BasicNameValuePair("name", str2));
    params.add(new BasicNameValuePair("username", LoginActivity.username));
    String result = httpConnect.getDataAsString(params);
    return result;
    }
    然后
    private String url;
    private HttpPost httpRequest;
    private HttpResponse httpResponse;
    private HttpParams httpParams;
    private HttpClient httpClient;
    //private static final String YES = "yes";
    private static final String NO = "no"; public HttpConnect(String url, Context context) {
    this.url = url;
    httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, 15000);
    HttpConnectionParams.setSoTimeout(httpParams, 15000);
    httpClient = new DefaultHttpClient(httpParams);
    }/**
     * Role:通过Http请求来获取返回值(String)
     * <BR>Date:2012-2-10
     * <BR>@author CODYY)peijiangping
     */
    public String getDataAsString(List<NameValuePair> params) {
    String result = null;
    try {
    httpRequest = new HttpPost(url);
    httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
    httpResponse = httpClient.execute(httpRequest);
    //System.out.println("httpResponse"+httpResponse.getStatusLine().getStatusCode()+"url:"+url);
    if (200 == httpResponse.getStatusLine().getStatusCode()) {
    result = EntityUtils.toString(httpResponse.getEntity());
    System.out.println("取得返回值" + result);
    if (result.equals(NO)) {
    return NO;
    } else {
    return result;
    }
    }
    } catch (IOException e) {
    return "error";
    }
    return NO;
    }
      

  4.   

    您好。我试下了下您的程序。android这边控制台输出error。还是隔一段时间报出:request time failed:java.net.socketException:Address family not supported by protocol.
      

  5.   

    你是用模拟器测试的吗?
    首先确定已经加上了<uses-permission android:name="android.permission.INTERNET" />
    权限
    如果加上了,
    你可以用真机试试,
    我之前用模拟器也出现过类似的问题,但用真机没问题,,或者你新建另一个模拟器,用新的模拟器看看,你的代码,和楼上提供的代码是没有问题的
      

  6.   

    很奇怪。之前用的有线,我的代码跟peijiangping1989的代码都有请求时失败那个问题。
    今天换成无线了,peijiangping1989的代码没有问题了。但是我的代码一会能打印服务器返回的参数,一会又不行。不知道这是什么情况。