【问题标题】:Socket Exception : Connection Reset for twilio API套接字异常:twilio API 的连接重置
【发布时间】:2019-01-21 13:04:36
【问题描述】:

我试图通过 twilio API 实现 whatapp messeging。 获取异常:

线程“主”com.twilio.exception.ApiException 中的异常:连接重置

我指的是this 的示例代码实现

public static void main( String[] args )
{

    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
    Message message = Message.creator(
            new com.twilio.type.PhoneNumber("whatsapp:+91xxxxxxxxxx"),
            new com.twilio.type.PhoneNumber("whatsapp:+91xxxxxxxxxx"),
            "Hello there!")
        .create();

    System.out.println(message.getSid());}
}

获取异常:

Exception in thread "main" com.twilio.exception.ApiException: Connection reset
    at com.twilio.http.NetworkHttpClient.makeRequest(NetworkHttpClient.java:128)
    at com.twilio.http.HttpClient.reliableRequest(HttpClient.java:42)
    at com.twilio.http.HttpClient.reliableRequest(HttpClient.java:25)
    at com.twilio.http.TwilioRestClient.request(TwilioRestClient.java:42)
    at com.twilio.rest.api.v2010.account.MessageCreator.create(MessageCreator.java:491)
    at com.twilio.rest.api.v2010.account.MessageCreator.create(MessageCreator.java:25)
    at com.twilio.base.Creator.create(Creator.java:45)
    at test.whatsaap.App.main(App.java:26)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:209)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
    at sun.security.ssl.InputRecord.read(InputRecord.java:503)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:396)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:355)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:373)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:394)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
    at com.twilio.http.NetworkHttpClient.makeRequest(NetworkHttpClient.java:120)
    ... 7 more

【问题讨论】:

    标签: java twilio-api


    【解决方案1】:

    我看到这是一个老问题,但我目前遇到了同样的问题,但我发现它只发生在 Java 7 上。当使用较新版本(如 Java 13)运行时,代码运行完美。如果您的环境允许使用更新的 Java 版本,那么它可能会很好。奇怪,因为 Twilio 支持 Java 7,但我没有运气在这个版本上发送任何请求。

    【讨论】:

      猜你喜欢
      • 2014-08-25
      • 2013-09-08
      • 2021-12-01
      • 1970-01-01
      • 2014-06-24
      • 2013-09-16
      • 2013-04-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多