网络权限已设置。隔几分钟出来一次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();
}
------解决方案--------------------
给你发个专业的http请求吧。。。
- Java code
/** * 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; }