最近正在测试消息传递网关的功能。 中国网建: http://www.smschinese.cn/default.shtml,在此网站注册账号。
可以免费发送5封邮件、3封彩色邮件。 另外,还可以自己多买邮件彩信。 如果有套餐的话就没那么贵了
这很方便。 代码如下。
importorg.Apache.com mons.http client.header;
importorg.Apache.com mons.http client.http client;
importorg.Apache.com mons.http client.namevaluepair;
importorg.Apache.com mons.http client.methods.post method;
公共类测试短信{
publicstaticvoidmain (string [ ] args ) throws Exception { )。
HTTP客户端=newhttp客户端(;
postmethodpost=new post method (http://gbk.SMS.web Chinese.cn );
post.addrequestheader (' content-type ',' application/x-www-form-urlencoded; charset=gbk '; //在头文件中设置转码
namevaluepair [ ] data={ newnamevaluepair ',' uid ','帐户',newnamevaluepair ',' key ','私钥'),
newnamevaluepair(SMSmob )、“移动电话号码”)、newnamevaluepair )、“SMStext”、“谷神通消息网关测试:授权码: 8888;
post.setrequestbody(data;
client.executemethod(post;
header [ ] headers=post.getresponse headers (;
int status code=post.get status code (;
system.out.println (statuscode : ) status code );
头:头(for ) {
system.out.println(h.tostring () );
}
string result=new string (post.getresponsebodyasstring ().getbytes('gbk ' ) );
system.out.println(result ); //打印回复消息的状态
post.releaseConnection (;
}
}