gpt4 book ai didi

java - 套接字异常: Connection Reset for twilio API

转载 作者:太空宇宙 更新时间:2023-11-04 09:54:48 25 4
gpt4 key购买 nike

我试图通过 twilio API 实现 Whatapp 消息传递。获取异常:

Exception in thread "main" com.twilio.exception.ApiException: Connection reset

我指的是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 7 上。当使用较新的版本(如 Java 13)运行时,代码运行完美。如果您的环境允许更新的 Java 版本,那么也许就可以了。奇怪的是,Twilio 支持 Java 7,但我没能在这个版本上用它发送任何请求。

关于java - 套接字异常: Connection Reset for twilio API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54290667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com