码迷,mamicode.com
首页 > 编程语言 > 详细

java 发送短信sms实现接口

时间:2015-01-29 19:38:43      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:java   短信   接口   java短信   java发送短信   

import java.io.UnsupportedEncodingException;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

public class SendMsg_webchinese {

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-logging-1.1.1.jar
commons-httpclient-3.1.jar
commons-codec-1.4.jar

java 发送短信sms实现接口

标签:java   短信   接口   java短信   java发送短信   

原文地址:http://blog.csdn.net/ve_love/article/details/43273997

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!