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- ...
随机推荐
- 【Away3D代码解读】其它一些的记录(持续更新)
查看当前正在使用的AGAL代码可以在程序开始时添加下面的代码,AGAL代码会被trace出来: Debug.active = true; 具体的输出是在MaterialPassBase类的update ...
- GDB 入门篇
调试流程:(使用gcc编译时加上 -g -Wall选项)gdb attach pidinfo bb filename:linenum / b filename:functionnamecp varia ...
- Oracle- 提示查询结果不可更新,请使用...更新结果。
我们在对Oracle数据库进行操作时,有时会在查询完结果后想要对其中的某些数据进行操作,当我们点击编辑(一个锁标志)是,会提示我们上述问题中的错误:这些查询结果不可更新,请使用ROWI或者SELECT ...
- IOS 在Ipad 横屏 上使用UIImagePickerController
转载前请注明来源:http://www.cnblogs.com/niit-soft-518/p/4381328.html 最近在写一个ipad的项目,该项目必须是横屏.进入正题,有一项功能是要调用系统 ...
- Aizu 2302 On or Off dfs/贪心
On or Off Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...
- 安装Windows SDK7.1时发生的一个错误(附解决办法)
A problem occurred while installing selected Windows SDK components. Installation of the "Micro ...
- 让DataGridView显示行号
http://www.cnblogs.com/JuneZhang/archive/2011/11/21/2257630.html 为了表示行号,我们可以在DataGridView的RowP ...
- 04---XML编程整理
一.XML概述 XML(eXtensible Markup Language),可扩展标记语言, 被设计的宗旨是传输数据,而非显示数据 W3C发布的,目前遵循1.0 ...
- js hash字符串转成json
var a='account.type=1&account.id=&account.dependFlag=0&account.card.companyId=1&acco ...
- javascript笔记04:let语句 和 yield语句 和 with语句
1.yield语句: <script type="application/javascript; version=1.7"> function generator() ...