Android弃用了apache模块(HttpClient,HttpResponse等)自API级别22以来,Android已经弃用了Apache模块,所以我的问题是,我如何使用,例如 HttpResponse来自Apache库,而不是Android SDK?问题是两个包都是一样的。但是,例如,HttpGet没关系,因为它HttpGetHC4在Apache中被调用。
3 回答
繁华开满天机
TA贡献1816条经验 获得超4个赞
HttpClient方法已被弃用。您现在可以使用URLConnection,如您在此示例中所示:
private StringBuffer request(String urlString) { // TODO Auto-generated method stub StringBuffer chaine = new StringBuffer(""); try{ URL url = new URL(urlString); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setRequestProperty("User-Agent", ""); connection.setRequestMethod("POST"); connection.setDoInput(true); connection.connect(); InputStream inputStream = connection.getInputStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream)); String line = ""; while ((line = rd.readLine()) != null) { chaine.append(line); } } catch (IOException e) { // Writing exception to log e.printStackTrace(); } return chaine;}
我希望这能帮助别人。
- 3 回答
- 0 关注
- 1311 浏览
添加回答
举报
0/150
提交
取消