首页 > 代码库 > HttpClient联网工具类
HttpClient联网工具类
public class HttpConnect { public static String getNews(String url,List<? extends NameValuePair> parameters) { StringBuilder sb = new StringBuilder(); HttpClient client = new DefaultHttpClient(); HttpPost post=new HttpPost(url); HttpParams params = client.getParams(); HttpConnectionParams.setConnectionTimeout(params, 5000); HttpConnectionParams.setSoTimeout(params, 5000); try { UrlEncodedFormEntity sendDate=new UrlEncodedFormEntity(parameters); post.setEntity(sendDate); HttpResponse response = client.execute(post); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); if (entity != null) { BufferedReader reader = new BufferedReader( new InputStreamReader(entity.getContent(), "UTF-8"), 8192); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } reader.close(); return sb.toString(); } } } catch (Exception e) { } return null; }
HttpClient联网工具类
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。