这是我试图通过红色氧气服务器发送短信的代码
这是我在 final String requestURL = " http://www.redoxygen.net/sms.dll?Action=SendSMS ";下面执行的代码
final StringBuilder stringBuilder = new StringBuilder();
try {
stringBuilder.append("AccountId=").append(URLEncoder.encode("****", "UTF-8"))
.append("&Email=").append(URLEncoder.encode("*******", "UTF-8"))
.append("&Password=").append(URLEncoder.encode("******", "UTF-8"))
.append("&Recipient=").append(URLEncoder.encode("******", "UTF-8"))
.append("&Message=").append(URLEncoder.encode("hello", "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
final URL address;
try {
address = new URL(requestURL);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
final HttpURLConnection connection;
try {
connection = (HttpURLConnection) address.openConnection();
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
connection.setRequestMethod("POST");
} catch (ProtocolException e) {
throw new RuntimeException(e);
}
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setConnectTimeout(100000000);
DataOutputStream output = null;
try {
output = new DataOutputStream(connection.getOutputStream());
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
output.writeBytes(stringBuilder.toString());
} catch (IOException e) {
throw new RuntimeException(e);
}
执行时出现以下异常:
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:525)
at sun.net.NetworkClient.doConnect(NetworkClient.java:158)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.http.HttpClient.New(HttpClient.java:323)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:860)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:801)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:726)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:904)
at com.nextenders.server.LoginServlet.SendSMS(LoginServlet.java:143)
我尝试增加连接 timeout
并关闭防火墙...等但没有运气。谁能帮我追踪问题?
这是我正在关注的教程: http ://www.redoxygen.com/developers/java/
我的代码中的“ * ”是网关的凭据。