09_httpclient测试SOAP协议
【工程截图】注意:无需使用Wsimport生成客户端代码

【HttpClient.java】
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL; public class HttpClient { public static void main(String[] args) throws IOException { //开启 一个http链接
//webservice地址
URL url = new URL("http://127.0.0.1:12345/weather"); HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); //设置post请求,post是大写
httpURLConnection.setRequestMethod("POST");
//Content-Type: text/xml; charset=utf-8
httpURLConnection.setRequestProperty("Content-Type", "text/xml; charset=utf-8"); //设置请求和响应
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true); String requestString = requestString("郑州");
//发送soap协议
httpURLConnection.getOutputStream().write(requestString.getBytes()); //接收响应内容 InputStream inputStream = httpURLConnection.getInputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); int len=-1;
byte[] b = new byte[1024];
//将inputStream内容写到byteArrayOutputStream
while((len= inputStream.read(b, 0, 1024))!=-1){
byteArrayOutputStream.write(b, 0, len);
} //获取响应内容
String responseString = byteArrayOutputStream.toString(); System.out.println(responseString); //解析响应的xml数据。
//....
inputStream.close();
byteArrayOutputStream.close();
} /**
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:queryWeather xmlns:ns2="http://server.weather.jaxws.Higgin.com/">
<arg0>郑州</arg0>
</ns2:queryWeather>
</S:Body>
</S:Envelope>
*/
//soap协议内容,请求的 内容
private static String requestString(String cityName){
String xmlString = "<?xml version=\"1.0\" ?>" +
"<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"<S:Body>" +
"<ns2:queryWeather xmlns:ns2=\"http://server.weather.jaxws.Higgin.com/\">" +
"<arg0>"+cityName+"</arg0>" +
"</ns2:queryWeather>" +
"</S:Body>" +
"</S:Envelope>";
return xmlString;
}
}
【运行结果】
(注意:要先开启WebService服务)

(需要进一步解析出自己所需的数据,使用正则表达式)
09_httpclient测试SOAP协议的更多相关文章
- Jmeter测试SOAP协议(Jmeter 3.3)
公司协议都是SOAP协议的,最初在网上看到Jmeter测试soap协议需要插件,但是Jmeter3.2开始就不在支持该插件,后来又查了些资料,找到了解决办法,Jmeter提供专门创建针对soap协议的 ...
- 10-jmeter 测试soap协议v1.2版本请求
1.因为jmeter安装了第三方插件jmeter-plugins-manager.jar之后(具体安装看之前文章),此时就可简单直接测试soap协议1.2版本的请求了 2. 3.进行运行线程就可实现了 ...
- jmeter3 测试soap协议-webservice接口
1.新建一个线程组 2.在线程组下新增,SOAP请求 3.设置soap请求,然后就可以测试了
- jmeter测试soap协议时候 路径不需要添加
- soap协议测试
soap就是http发送xml数据 1.soap协议提包含下列元素,红色标注为必须 2.soap消息基本结构 3.http+xml方式测试soap协议
- 【JMeter4.0学习(三)】之SoapUI创建WebService接口模拟服务端以及JMeter对SOAP协议性能测试脚本开发
目录: 创建WebService接口模拟服务端 下载SoapUI 新建MathUtil.wsdl文件 创建一个SOAP项目 接口模拟服务端配置以及启动 JMeter对SOAP协议性能测试脚本开发 [阐 ...
- lr使用soap协议,来对webservice接口进行测试
实际项目中基于WSDL来测试WebService的情况并不多,WSDL并不是WebService测试的最佳选择. 最主要的原因还是因为WSDL文档过于复杂. 在案例(天气预报WebService服务) ...
- 08_使用TCP/IP Monitor监视SOAP协议
[SOAP定义] SOAP 简单对象访问协议,基于http传输xml数据,soap协议体是xml格式.SOAP 是一种网络通信协议SOAP 即Simple Object Access Pr ...
- SoapUI SoapUI测试WebService协议接口简介
SoapUI测试WebService协议接口简介 by:授客 QQ:1033553122 1. 创建项目,入口:File -> New SOAP Project,或者右键默认项目Project- ...
随机推荐
- mysql之数据库备份与恢复
备份与恢复 系统运行中,增量备份与整体备份. 例如:每周日整体备份一次,周一到周六只备份当天. 如果周五的数据出了问题,可以用周日的整体+周一.周二.周三.周四来恢复. 备份的工具: 有第三方的收费备 ...
- dataGridView控件--未将对象引用设置添加到对象的实例
上篇博客中我完成了如何将控件中的数据导出到excel中dataGridView控件--导出Excel,当我成功导出后,又再次遇到了新问题---未将对象引用设置添加到对象的实例 解决办法: 1 .将代 ...
- AS问题解决系列3—iCCP: Not recognizing known sRGB profile
http://my.oschina.net/1pei/blog/479162 摘要 本文解决了Android Studio 1.2.2下编译期间出现的libpng warning: iCCP: Not ...
- js 如何将无限级分类展示出来
这个需要运用递归. 案例:将数据以 ul li ul li形式展现在div中. <div id="div"></div> 数据格式为json: var da ...
- Codeforces Round #324 (Div. 2) D. Dima and Lisa 哥德巴赫猜想
D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
- cocos2d-x3.1.1 step by step 学习笔记1----- 软件的安装与HelloWord
1:软件安装 系统:WIn7 软件:VS2012.cocosd-x3.1.1.python2.6.7.doxygen <1>首先安装VS2012,安装也是傻瓜式安装, <2>然 ...
- Nginx与Tomcat、Client之间请求的长连接配置不一致问题解决[转]
http://bert82503.iteye.com/blog/2152613 前些天,线上出现“服务端长连接与客户端短连接引起Nginx的Writing.Active连接数过高问题”,这个是由于“服 ...
- TQ210裸机编程(3)——按键(查询法)
首先查看TQ210的底板原理图 这次编程只操作KEY1和KEY2,在TQ210核心板原理图中搜索XEINT0 可以看出KEY1和KEY2分别接在S5PV210的GPH0_0和GPH0_1引脚. 这次编 ...
- iOS 开发中使用 NSURLProtocol 拦截 HTTP 请求
这篇文章会提供一种在 Cocoa 层拦截所有 HTTP 请求的方法,其实标题已经说明了拦截 HTTP 请求需要的了解的就是 NSURLProtocol. 由于文章的内容较长,会分成两部分,这篇文章介绍 ...
- python--while循环
1.最简单的while True循环 count = while True : : print('hello',count) break count += hello 2.利用while循环写一个猜年 ...