1.步骤与查看手机号码归属地博客是一样的。
代码如下:
package com.tools; import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMFactory; import org.apache.axiom.om.OMNamespace; import org.apache.axiom.soap.soAP11Constants; import org.apache.axis2.Constants; import org.apache.axis2.addressing.EndpointReference; import org.apache.axis2.client.Options; import org.apache.axis2.client.ServiceClient; import org.apache.axis2.transport.http.HTTPConstants; import org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class WeatherAxis { private static EndpointReference targetEPR = new EndpointReference( "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx"); // private static EndpointReference targetEPR = new EndpointReference( // "http://210.43.64.106/Service.asmx"); public void getResult() throws Exception { ServiceClient sender = new ServiceClient(); sender.setoptions(buildOptions()); OMElement result = sender.sendReceive(buildparam()); System.out.println(result); } private static OMElement buildparam() { OMFactory fac = OMAbstractFactory.getoMFactory(); OMNamespace omNs = fac.createOMNamespace("http://WebXml.com.cn/",""); // OMNamespace omNs = fac.createOMNamespace("http://tempuri.org/",""); OMElement data = fac.createOMElement("getWeatherbyCityName",omNs); // OMElement data = fac.createOMElement("XSCheckPassword",omNs); OMElement inner = fac.createOMElement("theCityName",omNs); // OMElement inner = fac.createOMElement("xh",omNs); inner.setText("吉首"); // OMElement inner2 = fac.createOMElement("xm",omNs); // inner.setText("2008198821"); data.addChild(inner); // data.addChild(inner2); return data; } private static Options buildOptions() { Options options = new Options(); options.setSoapVersionURI(SOAP11Constants.soAP_ENVELOPE_NAMESPACE_URI); options.setAction("http://WebXml.com.cn/getWeatherbyCityName"); // options.setAction("http://210.43.64.106/XSCheckPassword"); options.setTo(targetEPR); //options.setProperty 如果不是通过代理上网,此句可省 //options.setProperty(HTTPConstants.PROXY,buildProxy()); options.setTransportInProtocol(Constants.TRANSPORT_HTTP); return options; } /** * 本机采用代理服务器上网时,需要设置代理 * @return */ public static ProxyProperties buildProxy() { ProxyProperties proxyProperties = new ProxyProperties(); proxyProperties.setProxyName("代理名称"); proxyProperties.setProxyPort(8080); return proxyProperties; } public static void main(String[] args) throws Exception { WeatherAxis s = new WeatherAxis(); s.getResult(); } }
3.大功告成。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。