2

I just used Retrofit without OkHttp. Here is my code

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

            }
        });
    }

I aslo added OkHttp3 by researching the error.Here is the part that deals with 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();

But I got the same error.I think there is no need to add OkHttp3 for the error because previusly I worked with Retrofit without using OkHttp then it worked as expected. Here is the log output

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

1 Answer 1

3

Try to set writeTimeout() :

OkHttpClient OClient = new OkHttpClient.Builder();
OClient.connectTimeout(5, TimeUnit.MINUTES)
.writeTimeout(5, TimeUnit.MINUTES)
.readTimeout(5, TimeUnit.MINUTES);
Sign up to request clarification or add additional context in comments.

2 Comments

doesn't and will not work if writing request exceeds 5 minutes.
well it worked for me and some other people. Maybe something changed 3 years later though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.