java传输soap
2014-04-08 20:41
316 查看
public String postSoap(String soap, String requestName) throws IOException { // Post请求的url,与get不同的是不需要带参数 URL postUrl = new URL(POST_URL); // 打开连接 HttpURLConnection connection = (HttpURLConnection) postUrl .openConnection(); logger.info(requestName + " request: " + soap); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestMethod("POST"); connection.setUseCaches(false); connection.setInstanceFollowRedirects(true); connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8"); connection.setRequestProperty("SOAPAction", "http://ispp.com.cn/ispp_npi/SYNNPIAPI"); StringBuilder result = new StringBuilder(); BufferedReader reader = null; try { connection.connect(); DataOutputStream out = new DataOutputStream(connection .getOutputStream()); out.write(soap.getBytes("UTF-8")); out.flush(); out.close(); // flush and close reader = new BufferedReader(new InputStreamReader( connection.getInputStream())); String line; while ((line = reader.readLine()) != null) { result.append(line); } } catch (Exception e) { logger.error(requestName + " error: ", e); }finally{ reader.close(); connection.disconnect(); } return result.toString(); }
相关文章推荐
- spring3.0注解
- Java字节码
- (基于Java)算法之快速排序
- 在集群中java 通过调用API操作HBase 0.98
- Java命名约定
- java入门学习(四)
- c2java 第4篇 二叉堆和Huffman编码在视频编码中的运用
- spring 个人小心得
- Java 读取文件
- Java类加载机制
- Java方法的封装
- java自定义泛型
- (基于Java)算法之合并排序
- JAVA学习脚印8: 类及其成员的访问权限
- (基于Java)算法之二分搜索法
- JAVA学习脚印6: java方法调用机制
- struts2如何实现页面分步骤滑动
- JAVA学习脚印5: 继承特性及特殊类
- JAVA学习脚印4: 对象与类的概念
- MyEclipse + Maven开发Web工程的详细配置过程 .