HTTPCLIENT POST JSON
来源:互联网 发布:零售软件解决方案 编辑:程序博客网 时间:2024/06/10 15:24
private void httpReqUrl(List<HongGuTan> list, String url)throws ClientProtocolException, IOException {logger.info("httpclient执行新闻资讯接口开始。");JSONObject json = new JSONObject();DefaultHttpClient httpClient = new DefaultHttpClient();HttpPost method = new HttpPost(url);// 设置代理if (IS_NEED_PROXY.equals("1")) {HttpHost proxy = new HttpHost("192.168.13.19", 7777);httpClient.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy);}if (list != null && list.size() > 0) {logger.info("循环处理数据列表大小list.size={}", list != null ? list.size() : 0);// 开始循环组装post请求参数,使用倒序进行处理for (int i = list.size() - 1; i >= 0; i--) {HongGuTan bean = list.get(i);if (bean == null) {continue;}// 验证参数Object[] objs = { bean.getTitle(), bean.getContent(),bean.getSourceUrl(), bean.getSourceFrom(),bean.getImgUrls() };if (!validateData(objs)) {logger.info("参数验证有误。");continue;}// 接收参数json列表JSONObject jsonParam = new JSONObject();jsonParam.put("chnl_id", "11");// 红谷滩新闻资讯,channelId 77jsonParam.put("title", bean.getTitle());// 标题jsonParam.put("content", bean.getContent());// 资讯内容jsonParam.put("source_url", bean.getSourceUrl());// 资讯源地址jsonParam.put("source_name", bean.getSourceFrom());// 来源网站名称jsonParam.put("img_urls", bean.getImgUrls());// 采用 url,url,url 的格式进行图片的返回StringEntity entity = new StringEntity(jsonParam.toString(),"utf-8");//解决中文乱码问题 entity.setContentEncoding("UTF-8"); entity.setContentType("application/json"); method.setEntity(entity); //这边使用适用正常的表单提交 // List<BasicNameValuePair> pairList = new ArrayList<BasicNameValuePair>(); //pairList.add(new BasicNameValuePair("chnl_id", "11")); //pairList.add(new BasicNameValuePair("title", bean.getTitle()));// 标题 //pairList.add(new BasicNameValuePair("content", bean.getContent()));// 资讯内容 //pairList.add(new BasicNameValuePair("source_url", bean.getSourceUrl()));// 资讯源地址 //pairList.add(new BasicNameValuePair("source_name", bean.getSourceFrom()));// 来源网站名称 //pairList.add(new BasicNameValuePair("img_urls", bean.getImgUrls()));// 采用 url,url,url 的格式进行图片的返回 //method.setEntity(new UrlEncodedFormEntity(pairList, "utf-8")); HttpResponse result = httpClient.execute(method);// 请求结束,返回结果String resData = EntityUtils.toString(result.getEntity());JSONObject resJson = json.parseObject(resData);String code = resJson.get("result_code").toString(); // 对方接口请求返回结果:0成功 1失败logger.info("请求返回结果集{'code':" + code + ",'desc':'" + resJson.get("result_desc").toString() + "'}");if (!StringUtils.isBlank(code) && code.trim().equals("0")) {// 成功logger.info("业务处理成功!");} else {logger.error("业务处理异常");Constants.dateMap.put("lastMaxId", bean.getId());break;}}}}
0 0
- HTTPCLIENT POST JSON
- httpClient post发送json数据
- httpclient post 传json返回json
- Post Json 例子 Spring Rest Template & HttpClient
- HttpClient通过Post方式发送Json数据
- Java HttpClient Post多层json格式参数
- httpclient使用post提交json参数
- HttpClient通过Post方式发送Json数据
- HttpClient通过Post方式发送Json数据
- httpClient发送post请求,传递json字符串
- httpClient 发送 post请求 json数据
- 基于httpclient的post json方法
- HttpClient post请求 发送Json数据
- HttpClient上传Post请求和JSON请
- httpclient post发送json数组并解决json乱码问题
- HttpClient使用post和get时Json中文乱码解决方案
- 关于HttpClient post请求 传输json格式的字节流
- httpclient传json字符串raw形式,调post
- 深入分析Android开机找网延迟
- 计算1-1/2+1/3-1/4...+1/99-1/100的值
- struts2中接收请求参数(尤其是复合类型)
- 修改git commit 除了 git commit --amend 还有 git commmit rebase, reset
- A Comparison between Focus-Group and In-Depth Interview
- HTTPCLIENT POST JSON
- mongo的安装和部署
- mj使用
- CentOS 6.3 - 安装 Nginx 1.2.7(yum源)
- 调用notifyDataSetChanged方法失败的常见原因
- MFC SendMessage与PostMessage
- 判断1000-2000年的闰年
- Android 5.0 拨号流程
- 循环-01. 求整数段和(15)