我使用以下代码向用户发送短信
URL url = new URL(urlToHit);
HttpURLConnection http = (HttpURLConnection)url.openConnection();
switch (connection.getResponseCode()) {
case HttpURLConnection.HTTP_OK:
break;
case HttpURLConnection.HTTP_GATEWAY_TIMEOUT:
break;
case HttpURLConnection.HTTP_UNAVAILABLE:
break;
default:
LOGGER.error("Unknown response code");
}
以上代码工作正常,但有时会因Gatewal Timeout Exception
Caused by: java.io.IOException: Server returned HTTP response code: 504 for URL: `URL`
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1876)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
如果我错过上述代码发送短信,请建议。