发送SMS获取网关超时异常

时间:2018-04-23 13:33:12

标签: java

我使用以下代码向用户发送短信

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)

如果我错过上述代码发送短信,请建议。

0 个答案:

没有答案