JAVA发送HTTP请求与处理参考:
http://www.cnblogs.com/zhuawang/archive/2012/12/08/2809380.html
http://blog.csdn.net/atco/article/details/7949210
http://www.oschina.net/code/snippet_582384_44785
http://blog.csdn.net/rongyongfeikai2/article/details/41659353
JAVA设置代理服务器:
http://www.jb51.net/article/76309.htm
短信发送
WEB服务地址:http://117.79.237.5:8060/webservice.asmx?op=mt
调用:
/* * 方法名称:mt * 功 能:发送短信 * 参 数:mobile,content,ext,stime,rrid(手机号,内容,扩展码,定时时间,唯一标识) * 返 回 值:唯一标识,如果不填写rrid将返回系统生成的 */ public String mt(String mobile, String content, String ext, String stime, String rrid) { String result = ""; String soapAction = "http://tempuri.org/mt"; String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; xml += "<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/\">"; xml += "<soap:Body>"; xml += "<mt xmlns=\"http://tempuri.org/\">"; xml += "<sn>" + sn + "</sn>"; xml += "<pwd>" + pwd + "</pwd>"; xml += "<mobile>" + mobile + "</mobile>"; xml += "<content>" + content + "</content>"; xml += "<ext>" + ext + "</ext>"; xml += "<stime>" + stime + "</stime>"; xml += "<rrid>" + rrid + "</rrid>"; xml += "</mt>"; xml += "</soap:Body>"; xml += "</soap:Envelope>"; URL url; try { url = new URL(serviceURL); URLConnection connection = url.openConnection(); HttpURLConnection httpconn = (HttpURLConnection) connection; ByteArrayOutputStream bout = new ByteArrayOutputStream(); bout.write(xml.getBytes("GBK")); byte[] b = bout.toByteArray(); httpconn.setRequestProperty("Content-Length", String .valueOf(b.length)); httpconn.setRequestProperty("Content-Type", "text/xml; charset=gb2312"); httpconn.setRequestProperty("SOAPAction", soapAction); httpconn.setRequestMethod("POST"); httpconn.setDoInput(true); httpconn.setDoOutput(true); OutputStream out = httpconn.getOutputStream(); out.write(b); out.close(); InputStreamReader isr = new InputStreamReader(httpconn .getInputStream()); BufferedReader in = new BufferedReader(isr); String inputLine; while (null != (inputLine = in.readLine())) { Pattern pattern = Pattern.compile("<mtResult>(.*)</mtResult>"); Matcher matcher = pattern.matcher(inputLine); while (matcher.find()) { result = matcher.group(1); } } return result; } catch (Exception e) { e.printStackTrace(); return ""; } }
扫描二维码关注公众号,回复:
622084 查看本文章