Java http方式提交短信到短信网关

URL url = new URL("网关url");//使用post方式,这里不要带参数
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setConnectTimeout(5 * 1000);
// 设置连接超时时间
httpCon.setReadTimeout(30 * 1000);
//设置从主机读取数据超时(单位:毫秒)
httpCon.setDoOutput(true);
httpCon.setDoInput(true);
httpCon.setUseCaches(false);
httpCon.setRequestMethod("POST");
httpCon.setInstanceFollowRedirects(true);
httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            
String info = "发送的消息内容";
String encodeInfo = URLEncoder.encode(info, "UTF-8");
String phone = "15966378560";
//String phone = "15966378560,15966378560";//一般网关接口多号码发送都是用','隔开的;按网关开发文档修改

//请求的参数,根据网关开发文档来组装 
String content = "user=user&pwd=pwd&tel="+phone+"&info="+encodeInfo;
                   
byte[] postData = content.getBytes("UTF-8");
httpCon.setRequestProperty("Content-Length", String.valueOf(postData.length));
httpCon.connect();
DataOutputStream out = new DataOutputStream(httpCon.getOutputStream());
out.write(postData, 0, postData.length);
out.flush();
out.close();

int responseCode = httpCon.getResponseCode();
BufferedReader reader = new BufferedReader(new InputStreamReader(httpCon.getInputStream()));
while ((line = reader.readLine()) != null) {
     System.out.println(line);
}
reader.close();
String sRet = httpCon.getResponseMessage();
System.out.println("发送状态:" + sRet);
httpCon.disconnect();