httpclient使用post提交json参数,(跟使用表单提交区分)
来源:互联网 发布:冰种翡翠手镯价格知乎 编辑:程序博客网 时间:2024/04/29 20:13
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和Get提交参数
- HttpClient使用Post和Get提交参数
- HttpClient使用Post和Get提交参数
- HttpClient使用Post和Get提交参数
- HttpClient使用Post和Get提交参数
- HttpClient使用Post和Get提交参数
- HttpClient使用Post和Get提交参数
- 客户端使用httpclient提交json参数和解析json
- httpclient提交json参数
- httpclient提交json参数
- 使用post方式提交表单参数与值
- CURL模拟表单post提交及相关常用参数的使用(包括提交表单同时上传文件)
- CURL模拟表单post提交及相关常用参数的使用(包括提交表单同时上传文件)
- HttpClient 实现重定向 以表单方式post提交参数
- HttpClient使用get、post提交请求
- android中使用httpclient提交表单
- 解决virtuallBox安装Ubuntu后分辨率小的问题
- Linux kernel的中断子系统之(一):综述
- hdu - 4973 - A simple simulation problem.(线段树单点更新 + 区间更新)
- Linux kernel的中断子系统之(二):IRQ Domain介绍
- linux kernel的中断子系统之(三):IRQ number和中断描述符
- httpclient使用post提交json参数,(跟使用表单提交区分)
- linux kernel的中断子系统之(四):High level irq event handler
- 学习broadcast和service结合练习做了一个小型播放器,本周出正式版
- 可我只有两双布鞋
- Linux kernel中断子系统之(五):驱动申请中断API
- [Leet code 153, medium] Find Minimum in Rotated Sorted Array
- android端和Struts2服务器端通信,交互信息,参数采用JSON,使用了HttpClient与HttpPost类
- Linux kernel的中断子系统之(六):ARM中断处理过程
- HttpClient模拟get,post请求并发送请求参数(json等)