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- ...
随机推荐
- PJax在jQuery 3.0无法运行问题修复
PJax在jQuery 3.0无法运行 [现象] 页面报错:Uncaught TypeError: Cannot read property 'push' of undefined [原因] jQue ...
- cocos2d-x 网格动画深入分析
转自:http://www.2cto.com/kf/201212/179828.html 在TestCpp中的EffectsTest示例中展示了一些屏幕特效,它是将屏幕划分为多个格子,并对这些格子进行 ...
- 如何调试libc++abi.dylib handler threw exception错误
From:http://blog.csdn.net/naruto_ku/article/details/8779203 在进行iOS开发时,偶尔会碰到libc++abi.dylib handler t ...
- 免费开放的API
1)新浪IP地址查询API接口 http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=IP地址 format有 js. ...
- hadoop学习;block数据块;mapreduce实现样例;UnsupportedClassVersionError异常;关联项目源代码
对于开源的东东,尤其是刚出来不久,我认为最好的学习方式就是能够看源代码和doc,測试它的样例 为了方便查看源代码,关联导入源代码的项目 先前的项目导入源代码是关联了源代码文件 block数据块,在配置 ...
- php删除最后一个字符
原字符串1,2,3,4,5,6, 去掉最后一个字符",",最终结果为1,2,3,4,5,6 结合运用substr和strlen两个函数实现. 代码: $str = "1, ...
- 重启PHP命令
php-fpm重启 killall php-fpm 再执行(usr/local/php是php的安装目录)/usr/local/php/sbin/php-fpm & /usr/local/ng ...
- 删除vector中的偶数元素,删除list中的奇数元素
#include<vector> #include<list> #include<iostream> using namespace std; int main() ...
- mysql中的存储过程和事务隔离
※存储过程存储过程是保存在数据库上的一段可执行代码.1.定义存储过程的语法是:Create procedure sp_name (参数..)Begin SQL语句End;2.调用它的方法:Call s ...
- 关于JFace中的右键菜单Action类,ActgionGroup类,MenuManager类
Action类,ActionGroup类,MenuManager类介绍 SWT中菜单是Menu类,在前面章节中已经介绍过Menu类的使用. 菜单项用MeauItem类来实现.但是在实际开发中,同一种功 ...