httpclient
来源:互联网 发布:网络作家怎样赚钱 编辑:程序博客网 时间:2024/06/05 08:07
之前服务调用一用过直是用的dubbo,没有用过httpclient
这次试用感觉还是很简单的,上手简单,可能深入理解就没有那么简单了,下面简单写下上手使用的小demo
// 发送xml数据到服务HttpClientUtil httpClientUtil = new HttpClientUtil();String result = httpClientUtil.sendHttpPost("httpurl", outbound.getXMLString(a, b, c, d, e, f, g));System.out.println(result);String code = result.substring(result.indexOf("<statuscode>")+"<statuscode>".length(),result.indexOf("</statuscode>"));System.out.println(code);return code;
// 获取xmlpublic String getXMLString(Integer channelid, Integer customerid, long batchid, Integer mediatype, String media,String tels, String auth) {//String XML_HEADER = "<?xml version=\"1.0\"?>";StringBuffer sb = new StringBuffer();//sb.append(XML_HEADER);sb.append("<Request>");sb.append(" <a>" + a+ "</a>");sb.append(" <b>" + b+ "</b>");sb.append(" <c>" + c+ "</c>");sb.append(" <d>" + d+ "</d>");sb.append(" <e>" + e+ "</e>");sb.append(" <f>" + f+ "</f>");sb.append(" <g>" + g+ "</g>");sb.append("</Request>");// 返回String格式return sb.toString();}工具类
/** * 发送 post请求 * * @param httpUrl 地址 * @param params 参数(格式:key1=value1&key2=value2) */ public String sendHttpPost(String httpUrl, String params) { HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost try { //设置参数 StringEntity stringEntity = new StringEntity(params, "UTF-8"); stringEntity.setContentType("application/xml"); httpPost.setEntity(stringEntity); } catch (Exception e) { e.printStackTrace(); } return sendHttpPost(httpPost); }
0 0
- HttpClient
- HttpClient
- httpClient
- HttpClient
- HttpClient
- HttpClient
- HttpClient
- HttpClient
- HttpClient
- HttpClient
- HttpClient
- httpclient
- httpclient
- HttpClient
- HttpClient
- httpclient
- httpclient
- HttpClient
- POJ3041Asteroids(二分图最大匹配)
- 常见线程池和启动定时器线程池-笔记整理7
- C++第4次作业
- Linux内核分析课程-- 理解进程调度时机跟踪分析进程调度与进程切换的过程
- Python:Tkinter之Radiobutton
- httpclient
- Water problem HDU
- ob缓存
- nginx 配置手机设备和pc设备请求不同的后台
- 【神经网络与深度学习】【计算机视觉】SPPNet-引入空间金字塔池化改进RCNN
- 关于find命令的一个奇葩问题, 其实不奇葩------不过是软链在捣鬼而已
- Python 3.x中导入urllib出现AttributeError: module 'urllib' has no attribute 'urlopen'
- Water problem HDU
- 设计模式初谈