Android向Http服务器发送Http请求异常-UnknowHostException

public static String httpRequest(String url){ HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 30000); HttpConnectionParams.setSoTimeout(httpParams, 30000); //新建HttpClient对象 HttpClient httpClient = new DefaultHttpClient(httpParams); HttpGet httpGet = new HttpGet(url); try { HttpResponse response = httpClient.execute(httpGet); if (response.getStatusLine().getStatusCode()!=HttpStatus.SC_OK){ System.out.println("Bad Request!"); } System.out.println(response.toString()); return response.toString(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return "Something Wrong"; }

 

解决方案:

开放Internet访问权限

androidmanifest.xml

你可能感兴趣的:(android,String,HTTP服务器,url,internet)