本程序主要是运用了中国网建提供的SMS短信平台,这个短信平台基于java提供个专门的接口
public class SMS {
public static void main(String[] args)throws Exception
{
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("http://gbk.sms.webchinese.cn");
post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gbk");// 在头文件中设置转码
NameValuePair[] data ={ new NameValuePair("Uid", "爱新觉******");//注册的用户名
new NameValuePair("Key", "*************");//注册成功之后,登陆网站时需要的秘钥
new NameValuePair("smsMob","************");//要发送的目标手机号码
new NameValuePair("smsText","服务器已经宕机!请速度查看!!!------【**********公司】")};//短信内容
post.setRequestBody(data);
client.executeMethod(post);
Header[] headers = post.getResponseHeaders();
int statusCode = post.getStatusCode();
System.out.println("statusCode:"+statusCode);
for(Header h : headers)
{
System.out.println(h.toString());
}
String result = new String(post.getResponseBodyAsString().getBytes("gbk"));
System.out.println(result);
post.releaseConnection();
}
}
需要用到的JAR包:
commons-codec-1.4
commons-httpclient-3.1
commons-logging-1.1.1