我想通过手机短信发送网站发送短信。我试图通过使用下面的代码通过Java API发送短信。它没有显示任何错误,但消息没有被发送。短信不在手机上使用批量短信网站发送
String urlParameters="usr=username &pwd=1234 &ph=9015569447 &text=Hello";
//String request = "http://hapi.smsapi.org/SendSMS.aspx?";
String request="http://WWW.BULKSMS.FELIXINDIA.COM/send.php?";
try{
URL url = new URL(request);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
connection.setUseCaches (false);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
connection.disconnect();
}
catch(Exception ex)
{
System.out.print(ex);
}
为什么你总是打印'“消息未发送”'? – ppeterka 2013-03-07 10:17:12
它只是一个消息来检查它不会抛出异常没有别的 – 2013-03-07 10:19:45
然后它应该说“消息发送”,不是吗?或甚至更好的“消息发送完成” – ppeterka 2013-03-07 10:24:13