HttpClient运用二ITeye - 娱乐之横扫全球

HttpClient运用二ITeye

2019-01-12 09:45:58 | 作者: 鸿煊 | 标签: 实体,查询,数据 | 浏览: 699

HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "GBK"); HttpPost httpPost = new HttpPost(urlStr); String content="" ; try { if (params != null) { Iterator String keys = params.keySet().iterator(); List NameValuePair nvps = new ArrayList NameValuePair while (keys.hasNext()) { String key = keys.next(); nvps.add(new BasicNameValuePair(key, params.get(key))); httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); HttpResponse response = httpClient.execute(httpPost); HttpEntity entity = response.getEntity(); content = EntityUtils.toString(entity , "utf-8"); } catch (Exception e) { e.printStackTrace(); return content; * 查询list 实体 数据 * @Title getListFromUrl * @param url * @param params * @param clazz * @return * @return List T * @throws public static T extends Object List T getListFromUrl( String url, Map String, String params , Class T clazz ) { String result = getStrFromUrl(url,params); if(result==null || "".equals( result)){ return null ; JSONArray jsonarray = JSONArray.fromObject(result ); List T list = (List T )JSONArray.toList(jsonarray, clazz); return list; * 得到目标从实体里边 * @Title getEntityFromUrl * @param url * @param params * @param clazz * @return * @return T * @Description * @throws public static T extends Object T getEntityFromUrl( String url, Map String, String params , Class T clazz ) { String result = getStrFromUrl(url,params); if(result==null || "".equals( result)){ return null ; JSONObject jb = JSONObject.fromObject(result); T t = (T) JSONObject.toBean( jb, clazz ) ; return t ;
版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表娱乐之横扫全球立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章