发送短信sms
调用中国网建提供的SMS短信平台
public static void main(String[] args) {
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("http://gbk.api.smschinese.cn");
post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gbk");//在头文件中设置转码
NameValuePair[] data ={ new NameValuePair("Uid", "xiao**"),
new NameValuePair("Key", "bf83f********296"),
new NameValuePair("smsMob","1812****286"),
new NameValuePair("smsText","验证码:8888")};
post.setRequestBody(data);
try {
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); //打印返回消息状态
}catch (IOException e) {
e.printStackTrace();
}finally{
post.releaseConnection();
}
}
jar(commons-codec、commons-httpclient、commons-logging)