final String userName = "注册用户名";
final String key = "接口鉴权KEY";
final String mobileNos = "要发送的手机号码,多个用逗号隔开";
final String content = "验证码:8888";
//https协议请改用https://api.smslong.cn/ 短信接口
final String url = "http://api.smslong.cn:8082/";
Map<String, String> personMap = new HashMap<String, String>();
personMap.put("user", userName);
personMap.put("key", key);
personMap.put("mobile", mobileNos);
personMap.put("content", content);
List<NameValuePair> list = new LinkedList<NameValuePair>();
for (Entry<String, String> 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{}");
}