private static final String SMS_USER = "*****";
private static final String SMS_PWD = "*****";
private static final String SMS_METHOD_SEND = "*****";
/**
* 注册的激活码
* @param mobile
* @param code
* @throws IOException
*/
public static void sendActiveSMS(String mobile, String code) throws IOException {
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("*************************");
post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");//在头文件中设置转码
NameValuePair[] data ={
new NameValuePair("action", SMS_METHOD_SEND),
new NameValuePair("user", SMS_USER),
new NameValuePair("mobile", mobile),
new NameValuePair("content","***网站注册验证码:" + code + ",如非您本人操作,本信息可忽略。全国服务热线4000178999。"),
new NameValuePair("time",""),
new NameValuePair("msgid",""),
new NameValuePair("hashcode",SMS_PWD)};
post.setRequestBody(data);
client.executeMethod(post);
Header[] headers = post.getResponseHeaders();
int statusCode = post.getStatusCode();
for(Header h : headers) {
}
String result = new String(post.getResponseBodyAsString().getBytes("UTF-8"));
post.releaseConnection();
}
java模拟http请求给手机发短信
最新推荐文章于 2022-12-19 15:56:53 发布