Java 使用 SOAP 获取 webservice 实例解析
1. webservice 提供方: http://www.webxml.com.cn/zh_cn/index.aspx
2. 下面我们以 获取天气预报 为例。
参数截图如下图:
[http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?op=getWeatherbyCityN
import java.net.*;
import java.util.Vector;
String urlString = "http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx";
String xmlFile = "QQOnlineService.XML";
String soapActionString = "http://WebXml.com.cn/qqCheckOnline";
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
byte[] buf=new byte[(int)fileToSend.length()];
new FileInputStream(xmlFile).read(buf);
httpConn.setRequestProperty( "Content-Length",String.valueOf( buf.length ) );
httpConn.setRequestProperty("Content-Type","text/xml; charset=utf-8");
httpConn.setRequestProperty("soapActionString",soapActionString);
httpConn.setRequestMethod( "POST" );
httpConn.setDoInput(true);
评论0
最新资源