加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

手动发送xml报文调用webservice

发布时间:2020-12-15 23:13:04 所属栏目:百科 来源:网络整理
导读:public String sendMessageByWebService2(String phone,String msg,String... args){String webserviceUrl = PropertiesHandle.readValue("SMS.webserviceurl");String userName = PropertiesHandle.readValue("SMS.webserviceusername");String mainCode =
public String sendMessageByWebService2(String phone,String msg,String... args){
		String webserviceUrl = PropertiesHandle.readValue("SMS.webserviceurl");
		String userName = PropertiesHandle
				.readValue("SMS.webserviceusername");
		String mainCode = PropertiesHandle
				.readValue("SMS.webservicemaincode");
		String pwd = PropertiesHandle.readValue("SMS.webservicepwd");
		String RmTfh = PropertiesHandle.readValue("SMS.webservicermtfh");
		String result = "";
		URL url = null;
		StringBuffer sb = new StringBuffer();
		sb.append("<?xml version="1.0" encoding="UTF-8"?>");
		sb
				.append("<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">");
		sb.append("<soap:Body>");
		sb
				.append("<ns1:getBalance xmlns:ns1="http://webService.sooyie.com/">");
		sb.append("<arg0>"+mainCode+"</arg0>");
		sb.append("<arg1>"+pwd+"</arg1>");
		sb.append("</ns1:getBalance>");
		sb.append("</soap:Body></soap:Envelope>");
		try {
			url = new URL(webserviceUrl);
		} catch (MalformedURLException e1) {

			e1.printStackTrace();
		}
		URLConnection uc = null;
		OutputStreamWriter out = null;
		BufferedReader rd = null;
		try {
			uc = url.openConnection();
			uc.setDoOutput(true); // ....必须设置为'true'.
			uc.setRequestProperty("Content-Type","text/xml"); // 记住这行不能少否则会出错
			out = new OutputStreamWriter(uc.getOutputStream(),"utf-8");
			out.write(sb.toString());
			out.flush();
			out.close();

			rd = new BufferedReader(new InputStreamReader(uc.getInputStream(),"utf-8"));
			StringBuffer responseStr = new StringBuffer();
			String str;
			while ((str = rd.readLine()) != null) {
				responseStr.append(str);
			}
			result = responseStr.substring(responseStr.indexOf("<return>") + 8,responseStr.indexOf("</return>"));
			System.out.println(result);
			rd.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
return result;

	}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读