gpt4 book ai didi

android - java.net.SocketTimeoutException : timeout when used Retrofit with use or without use of OkHttp

转载 作者:搜寻专家 更新时间:2023-11-01 09:27:55 27 4
gpt4 key购买 nike

我只是在没有 OkHttp 的情况下使用了 Retrofit。这是我的代码

private void executeForm(String pubToken,String acctToken,Integer Amt,String UID){
Gson gson = new GsonBuilder()
.setLenient()
.create();

Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl(" https://us-central1-deyapay-192704.cloudfunctions.net/plaidCredentialsAddMoney/")
.addConverterFactory(GsonConverterFactory.create(gson));
Retrofit retrofit = builder.build();

APIService apiservice=retrofit.create(APIService.class);
Call<PostData> call=apiservice.achPost(pubToken,acctToken,Amt,UID);
call.enqueue(new Callback<PostData>() {
@Override
public void onResponse(Call<PostData> call, Response<PostData> response) {
if(response.isSuccessful()){
response.body();
String dp = response.body().getToken();
Log.d(TAG,dp);

Toast.makeText(ACH.this,"success",Toast.LENGTH_SHORT).show();
}
else
{

}
}

@Override
public void onFailure(Call<PostData> call, Throwable t) {
t.printStackTrace();
Log.e(TAG,t.toString());

}
});
}

我还通过研究错误添加了 OkHttp3。这是处理 OkHttp3 的部分

OkHttpClient OClient = new OkHttpClient.Builder()
.readTimeout(60,TimeUnit.SECONDS)
.connectTimeout(60, TimeUnit.SECONDS)
.build();
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl(" https://us-central1-deyapay-192704.cloudfunctions.net/plaidCredentialsAddMoney/")
.client(OClient)
.addConverterFactory(GsonConverterFactory.create(gson));
Retrofit retrofit = builder.build();

但我遇到了同样的错误。我认为没有必要为错误添加 OkHttp3,因为以前我在不使用 OkHttp 的情况下使用 Retrofit,然后它按预期工作。这是日志输出

03-24 16:16:45.591 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: java.net.SocketTimeoutException: timeout
03-24 16:16:45.592 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.internal.http2.Http2Stream$StreamTimeout.newTimeoutException(Http2Stream.java:593)
03-24 16:16:45.592 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.internal.http2.Http2Stream$StreamTimeout.exitAndThrowIfTimedOut(Http2Stream.java:601)
03-24 16:16:45.592 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.internal.http2.Http2Stream.takeResponseHeaders(Http2Stream.java:146)
03-24 16:16:45.592 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.internal.http2.Http2Codec.readResponseHeaders(Http2Codec.java:125)
03-24 16:16:45.592 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
03-24 16:16:45.592 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
03-24 16:16:45.592 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
03-24 16:16:45.592 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
03-24 16:16:45.592 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
03-24 16:16:45.593 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
03-24 16:16:45.593 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
03-24 16:16:45.593 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
03-24 16:16:45.593 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
03-24 16:16:45.593 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
03-24 16:16:45.593 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
03-24 16:16:45.593 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
03-24 16:16:45.593 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
03-24 16:16:45.593 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
03-24 16:16:45.593 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147)
03-24 16:16:45.593 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
03-24 16:16:45.593 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
03-24 16:16:45.593 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-24 16:16:45.593 28361-28361/com.bodaty.deyaPay.deyaPay W/System.err: at java.lang.Thread.run(Thread.java:818)
03-24 16:16:45.593 28361-28361/com.bodaty.deyaPay.deyaPay E/MyActivity: java.net.SocketTimeoutException: timeout

最佳答案

尝试设置writeTimeout():

OkHttpClient OClient = new OkHttpClient.Builder();
OClient.connectTimeout(5, TimeUnit.MINUTES)
.writeTimeout(5, TimeUnit.MINUTES)
.readTimeout(5, TimeUnit.MINUTES);

关于android - java.net.SocketTimeoutException : timeout when used Retrofit with use or without use of OkHttp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49464021/

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