社区
Java
帖子详情
java 调用webservice 接口发短信
wlaqianqian34
2012-01-17 11:47:27
就给了个地址:http://61.191.40.242:9090/WebService/EntInterface.asmx
要查看接口的定义的话则在连接地址下面增加“?WSDL”,
即http://61.191.40.242:9090/WebService/EntInterface.asmx?WSDL
请问根据这个如何实现java发短信?
...全文
298
2
打赏
收藏
java 调用webservice 接口发短信
就给了个地址:http://61.191.40.242:9090/WebService/EntInterface.asmx 要查看接口的定义的话则在连接地址下面增加“?WSDL”, 即http://61.191.40.242:9090/WebService/EntInterface.asmx?WSDL 请问根据这个如何实现java发短信?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
ai523730098
2012-01-17
打赏
举报
回复
weather.xml的内容是
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getWeatherbyCityName xmlns="http://WebXml.com.cn/">
<theCityName>${city}$</theCityName>
</getWeatherbyCityName>
</soap:Body>
</soap:Envelope>
放工程目录下就行了
ai523730098
2012-01-17
打赏
举报
回复
我可以给你两个例子参考下
第一个根据城市取天气
webservice的地址:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
运行下面的代码试试,实际上就是发请求给这个地址,请求的内容是有一定规则的xml字符串而已。
调用websevice接口的时候,可以首先用soapui调试下。
也可以用工具生成java代码的,生成代码的方法有很多,网上试试
package myweather;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class MyWeather {
private static String getSoapRequest(String city) {
try {
InputStreamReader isr = new InputStreamReader(new FileInputStream("weather.xml"));
BufferedReader reader = new BufferedReader(isr);
String soap = "";
String tmp;
while ((tmp = reader.readLine()) != null) {
soap += tmp;
}
reader.close();
isr.close();
return soap.replace("${city}$", city);
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
private static InputStream getSoapInputStream(String city) throws Exception {
try {
String soap = getSoapRequest(city);
if (soap == null) {
return null;
}
URL url = new URL("http://www.webxml.com.cn/WebServices/WeatherWebService.asmx");
URLConnection conn = url.openConnection();
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestProperty("Content-Length", Integer.toString(soap.length()));
conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
conn.setRequestProperty("SOAPAction","http://WebXml.com.cn/getWeatherbyCityName");
OutputStream os = conn.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os, "utf-8");
// osw.write(new String(soap.getBytes(),"utf-8"));
osw.write(soap);
osw.flush();
osw.close();
InputStream is = conn.getInputStream();
return is;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static String getWeather(String city) {
try {
Document doc;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream is = getSoapInputStream(city);
doc = db.parse(is);
NodeList nl = doc
.getElementsByTagName("getWeatherbyCityNameResult");
Node n = nl.item(0);
// JOptionPane.showMessageDialog(null,n.getChildNodes().getLength());
for (int i = 0; i < n.getChildNodes().getLength() - 1; i++) {
String weather = n.getChildNodes().item(i).getTextContent();
System.out.print(weather);
}
is.close();
return "null";
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void main(String[] args) throws Exception {
// System.out.println(MyWeather.getWeather("上海"));
MyWeather.getWeather("长沙");
}
}
// 将以下XML保存为weather.xml
/*
* XML:<?xml version="1.0" encoding="utf-8"?> <soap:Envelope
* xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
* xmlns:xsd="http://www.w3.org/2001/XMLSchema"
* xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body>
* <getWeatherbyCityName xmlns="http://WebXml.com.cn/">
* <theCityName>${city}$</theCityName> </getWeatherbyCityName> </soap:Body>
* </soap:Envelope>
*/
Java
之HttpClient
调用
WebService
接口
发送短信源码实战
本文详细介绍了使用
Java
的HttpClient
调用
WebService
接口
发送短信的过程。从
接口
文档和WSDL入手,逐步解析并演示了四种不同的HttpClient
调用
方法。此外,还重点讲解了封装soapXml的核心方法,并展示了最终的
调用
结果及短信接收情况。
Java
调用
WebService
接口
实现发送手机短信验证码功能
本文详细介绍了一个基于第三方短信平台
接口
的短信验证码实现方案,包括前端页面设计、
Java
Script交互逻辑及后端处理流程。通过具体代码示例,展示了如何发送验证码、验证用户输入等内容。
vue
调用
webservice
_浅谈
WebService
的
调用
本文介绍了作者在公司项目中使用Vue
调用
WebService
的经历,包括
WebService
的基本概念、
调用
方式,如通过WSDL生成代理类和Endpoint
调用
。详细讲述了如何在IntelliJ IDEA中创建
WebService
客户端,自动生成代理类,并提供了相关的依赖配置。文章最后提到了测试效果和不生成代理类的Endpoint
调用
方式。
java
通过org.apache.axis发送http请求
调用
c#写的
webService
短信
接口
本文记录了如何使用
Java
的org.apache.axis库发送HTTP请求
调用
C#编写的
WebService
短信
接口
。通过XML格式交互,成功实现了系统的短信验证功能。
请求
WebService
接口
_渣渣工作记录20201119
该博客围绕web项目新增定时
发短信
功能,介绍请求
WebService
短信
接口
的方法。可根据wsdl链接保存文件到本地生成客户端代码,还提及所需jar包及下载地。同时分享踩坑经历,给出RPC方式代码示例但作者未成功。
Java
51,409
社区成员
86,085
社区内容
发帖
与我相关
我的任务
Java
Java相关技术讨论
复制链接
扫一扫
分享
社区描述
Java相关技术讨论
java
spring boot
spring cloud
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章