webservice 中的map问题
来源:互联网 发布:网页美工教程 编辑:程序博客网 时间:2024/06/14 22:52
在做项目的时候 看到对方的接口需要传递map,当时心里想,map不是序列化的数据是不能传递的,
结果借助webservice可视化工具soapui查看了接口数据如下
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.wsjk.uniwin.com"> <soapenv:Header/> <soapenv:Body> <ser:addFileInfo> <ser:key>123</ser:key> <ser:map> <!--Zero or more repetitions:--> <ser:entry> <!--Optional:--> <ser:key>?</ser:key> <!--Optional:--> <ser:value>?</ser:value> </ser:entry> </ser:map> </ser:addFileInfo> </soapenv:Body></soapenv:Envelope>
灵机一动,这样子可以使用这种方式传递的。
具体代码如下:
URL url = new URL("http://localhost:8081/XFireTest/services/HelloService"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //是否具有输入参数 conn.setDoInput(true); //是否输出输入参数 conn.setDoOutput(true); //发POST请求 conn.setRequestMethod("POST"); //设置请求头(注意一定是xml格式) conn.setRequestProperty("content-type", "text/xml;charset=utf-8"); // 构造请求体,符合SOAP规范(最重要的) 工具的话 可以使用soapUI String requestBody = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " + "xmlns:ser=\"http://service.test.com\">" + "<soapenv:Header/><soapenv:Body><ser:sayHello>" + "<ser:in0>girl</ser:in0></ser:sayHello>" + "</soapenv:Body></soapenv:Envelope>"; //获得一个输出流 OutputStream out = conn.getOutputStream(); out.write(requestBody.getBytes()); //获得服务端响应状态码 int code = conn.getResponseCode(); StringBuffer sb = new StringBuffer(); if(code == 200){ //获得一个输入流,读取服务端响应的数据 InputStream is = conn.getInputStream(); byte[] b = new byte[1024]; int len = 0; while((len = is.read(b)) != -1){ String s = new String(b,0,len,"utf-8"); sb.append(s); } is.close(); } out.close(); System.out.println("服务端响应数据为:"+sb.toString());
这样就可以使用map了。
完整的webservicedemo下载地址:http://download.csdn.NET/detail/bestxiaok/9909002
阅读全文
0 0
- webservice 中的map问题
- Map分组中的问题
- Python3中的map问题
- WebService中的用户验证问题
- google map 与 webservice
- webservice传值list<map>
- ArcIMS 中的javaConnector初始化Map问题
- Cascaded Shadow Map(CSM)中的一些问题
- Cascaded Shadow Map(CSM)中的一些问题
- google map v2 在使用中的问题
- STL中的map表的使用问题
- Cascaded Shadow Map(CSM)中的一些问题
- Erlang map 中的非法匹配问题
- Erlang map 中的非法匹配问题
- Cascaded Shadow Map(CSM)中的一些问题
- map-reduce阶段中的数据倾斜问题
- 多分类问题中的mAP计算
- Webservice问题
- 手动卸载office 2010 亲测有效
- EAS 自动获取ID
- 【原创】【一套NOIP膜你赛】【大水题】第一题 膜拜azui
- JSP&Servlet --- JSP DAO模式
- mysql基本用法
- webservice 中的map问题
- 前端构建工具gulpjs的使用介绍及技巧
- 抽象类与一般类的区别
- 原生和jQuery的ajax用法
- jquery实现图片上传前本地预览功能
- Visual Studio IDE功能导览
- Android EditText的设置
- Jackson使用总结
- R语言 警告信息关闭