final String userName = "注册用户名";
final String key = "接口鉴权KEY";
final String mobileNos = "要发送的手机号码,多个用逗号隔开";
final String content = "验证码:8888";
//https协议请改用https://api.smschn.cn/ 短信接口
final String url = "http://api.smschn.cn:8082/";
Map personMap = new HashMap();
personMap.put("user", userName);
personMap.put("key", key);
personMap.put("mobile", mobileNos);
personMap.put("content", content);
List list = new LinkedList();
for (Entry entry : personMap.entrySet()){
list.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
HttpPost httpPost = new HttpPost(url);
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(list, "gbk");
httpPost.setEntity(formEntity);
HttpClient httpCient = HttpClients.createDefault();
HttpResponse httpresponse = null;
try{
httpresponse = httpCient.execute(httpPost);
HttpEntity httpEntity = httpresponse.getEntity();
String response = EntityUtils.toString(httpEntity, "gbk");
System.out.println("http状态码:"+response);
}
catch (ClientProtocolException e){
System.out.println("http请求失败,uri{},exception{}");
}
catch (IOException e){
System.out.println("http请求失败,uri{},exception{}");
}