我想通過手機短信發送網站發送短信。我試圖通過使用下面的代碼通過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