实验之——读取指定城市的天气预报,给指定手机发送验证码
(一)读取指定城市的天气预报
实验工具:IDEA
1、代码
package com.yuan;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.text.ParseException;
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 wjwz {
//method 要调用的webservie方法名,paramName请求参数名,paramValue请求参数值
private static String makeSoapRequest(String method,String paramName,String paramValue) {
StringBuffer sb = new StringBuffer();
sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
sb.append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
sb.append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ");
sb.append("xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
// 构造请求内容,这里需要将XXX替换为webservice的地址
sb.append("<soap:Body><"+method+" xmlns=\"http://WebXml.com.cn/\"><"+paramName+">" + paramValue + "</"+paramName+"></"+method+"></soap:Body>");
sb.append("</soap:Envelope>");