//1,首先创建一个URL对象
URL url = new URL(" http://m.5c.com.cn");
//2,开起一个到目标地址的连接,使用url创建一个连接对象
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
//3,设置相关属性
conn.setRequestMethod("POST");
//设置输出实体内容 表示我要输出
conn.setDoOutput(true);
//设置输出内容 ,实体内容可以使用拼接的内容
StringBuilder sb = new StringBuilder(100).append("username=").append(this.username)
.append("&password=").append(this.password).append("&apikey=").append(this.apikey).append("&phoneNumber=")
.append(phoneNumber).append("&content=").append("你收到的验证码是:").append(code).append(",请及时使用,有效时间为")
.append(BidConst.VERIFYCODE_VALIDATE_MIN).append("分鐘内使用");
conn.getOutputStream().write(sb.toString().getBytes());
//发送
conn.connect();
//获得相应内容
String ret = StreanUtils.copyToString(conn,getInputStream(),Charset.forName("UTF-8"));
if(ret.indexOf("success:") == 0){
//VerifyCodeVO里面是有三个字段,一个是保存电话号码,验证码和发送日期
vo=new VerifyCodeVO(phoneNumber, code, new Date());
//创建一个vo并存放到session里面
UserContext.setVerifyCode(vo);
}else{
//发送失败
}
URL url = new URL(" http://m.5c.com.cn");
//2,开起一个到目标地址的连接,使用url创建一个连接对象
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
//3,设置相关属性
conn.setRequestMethod("POST");
//设置输出实体内容 表示我要输出
conn.setDoOutput(true);
//设置输出内容 ,实体内容可以使用拼接的内容
StringBuilder sb = new StringBuilder(100).append("username=").append(this.username)
.append("&password=").append(this.password).append("&apikey=").append(this.apikey).append("&phoneNumber=")
.append(phoneNumber).append("&content=").append("你收到的验证码是:").append(code).append(",请及时使用,有效时间为")
.append(BidConst.VERIFYCODE_VALIDATE_MIN).append("分鐘内使用");
conn.getOutputStream().write(sb.toString().getBytes());
//发送
conn.connect();
//获得相应内容
String ret = StreanUtils.copyToString(conn,getInputStream(),Charset.forName("UTF-8"));
if(ret.indexOf("success:") == 0){
//VerifyCodeVO里面是有三个字段,一个是保存电话号码,验证码和发送日期
vo=new VerifyCodeVO(phoneNumber, code, new Date());
//创建一个vo并存放到session里面
UserContext.setVerifyCode(vo);
}else{
//发送失败
}