简体   繁体   English

套接字异常:twilio API 的连接重置

[英]Socket Exception : Connection Reset for twilio API

I was trying to implement whatapp messeging thro' twilio API.我试图通过 twilio API 实现 whatapp 消息传递。 Gettting exception:获取异常:

Exception in thread "main" com.twilio.exception.ApiException: Connection reset线程“main”com.twilio.exception.ApiException 中的异常:连接重置

I was referring this for sample code implementation我是指这个示例代码执行

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());}
}

Getting exception:获取异常:

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

I see that this is an old question but I am currently having the same issue, but I find that it only happens with Java 7. When run with a newer version, like Java 13, the code runs flawlessly.我看到这是一个老问题,但我目前遇到了同样的问题,但我发现它只发生在 Java 7 中。当使用更新版本(如 Java 13)运行时,代码运行完美无缺。 If your environment allows for a newer Java version then perhaps it will be fine.如果您的环境允许使用较新的 Java 版本,那么可能没问题。 Odd since Twilio supports Java 7 but I have had no luck sending any requests with it on this version.奇怪,因为 Twilio 支持 Java 7,但我没有运气在这个版本上发送任何请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM