【工程截图】注意:无需使用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协议的更多相关文章

  1. Jmeter测试SOAP协议(Jmeter 3.3)

    公司协议都是SOAP协议的,最初在网上看到Jmeter测试soap协议需要插件,但是Jmeter3.2开始就不在支持该插件,后来又查了些资料,找到了解决办法,Jmeter提供专门创建针对soap协议的 ...

  2. 10-jmeter 测试soap协议v1.2版本请求

    1.因为jmeter安装了第三方插件jmeter-plugins-manager.jar之后(具体安装看之前文章),此时就可简单直接测试soap协议1.2版本的请求了 2. 3.进行运行线程就可实现了 ...

  3. jmeter3 测试soap协议-webservice接口

    1.新建一个线程组 2.在线程组下新增,SOAP请求 3.设置soap请求,然后就可以测试了

  4. jmeter测试soap协议时候 路径不需要添加

  5. soap协议测试

    soap就是http发送xml数据 1.soap协议提包含下列元素,红色标注为必须 2.soap消息基本结构 3.http+xml方式测试soap协议

  6. 【JMeter4.0学习(三)】之SoapUI创建WebService接口模拟服务端以及JMeter对SOAP协议性能测试脚本开发

    目录: 创建WebService接口模拟服务端 下载SoapUI 新建MathUtil.wsdl文件 创建一个SOAP项目 接口模拟服务端配置以及启动 JMeter对SOAP协议性能测试脚本开发 [阐 ...

  7. lr使用soap协议,来对webservice接口进行测试

    实际项目中基于WSDL来测试WebService的情况并不多,WSDL并不是WebService测试的最佳选择. 最主要的原因还是因为WSDL文档过于复杂. 在案例(天气预报WebService服务) ...

  8. 08_使用TCP/IP Monitor监视SOAP协议

    [SOAP定义] SOAP   简单对象访问协议,基于http传输xml数据,soap协议体是xml格式.SOAP   是一种网络通信协议SOAP   即Simple Object Access Pr ...

  9. SoapUI SoapUI测试WebService协议接口简介

    SoapUI测试WebService协议接口简介 by:授客 QQ:1033553122 1. 创建项目,入口:File -> New SOAP Project,或者右键默认项目Project- ...

随机推荐

  1. mac不可或缺的套件管理器Homebrew

    Homebrew 1.简介 可以帮助我们快速安装软件, 如 brew install svn 快速卸载软件 , 如  brew uninstall svn 2.下载 打开终端, /usr/bin/ru ...

  2. Win8.1激活

    激活查询:在桌面状态下输入“Win+R”,进入运行栏目,输入slmgr.vbs -dlv 显示:最为详尽的激活信息,包括:激活ID.安装ID.激活截止日期 http://www.nruan.com/w ...

  3. c++ 操作注冊表

    1.       注冊表简单介绍 注冊表是为Windows NT和Windows95中全部32位硬件/驱动和32位应用程序设计的数据文件,用于存储系统和应用程序的设置信息.16位驱动在Winnt (W ...

  4. [React Fundamentals] Component Lifecycle - Mounting Usage

    The previous lesson introduced the React component lifecycle mounting and unmounting. In this lesson ...

  5. windows MySQL 5+ 服务手动安装

    一.手动安装mysql 1.准备一个mysql免安装版本(把原来安装好的版本复制一份即可.一次安装多次使用^_^),将mysql复制到指定目录. 2.配置my.ini文件(本例使用的是5.0.22版本 ...

  6. Mysql导出表结构及表数据 mysqldump用法

    几个常用用例: 1.导出整个数据库 mysqldump -u 用户名 -p 数据库名 > 导出的文件名     mysqldump -u wcnc -p smgp_apps_wcnc >  ...

  7. Cstring到string

    要利用mfc,然后接受一个图片. imread只能读const string& filename 的东西. imread 原型: CV_EXPORTS_W Mat imread( ); 它的参 ...

  8. SQL中N $ # @的作用

    declare @sql nvarchar(4000) set @sql= N'select @TotalRecords=count(*) from ' + N'(' + @sqlFullPopula ...

  9. 焦点轮播图——myfocus焦点图库

    网站网址: http://demo.jb51.net/js/myfocus/demo.html 简单3步,你即可以用上myFocus. Step 1. 在html的标签内引入相关文件 <scri ...

  10. mysql修改主键

    先删除所有主键 alter table tableName drop primary key; 然后添加主键 alter table tableName primary key(id);//如果是联合 ...