Lending Square
Lending Square

Reputation: 201

Server Timeout for Android Retrofit Post Requests

I send some data to the data which includes a users details when the user wants to signup. I tried using Postman and the records are added successfully. Any post request i make returns Timeout but the data is still sent to the server. What could be the issue since i dont get any issues with my GET requests.

This is my API Service below:

@POST("/api/account/usersignup/")
@FormUrlEncoded
Call<LendingResponse> savePost(@Field("phoneNumber") String phoneNumber,
                    @Field("name") String name,
                    @Field("email") String email,
                    @Field("password") String password,
                    @Field("confirmPassword") String confirmPassword);

This is my method for saving invoking the API below:

public void sendPost(String userPhone, String userName, String userEmail, String userPassword, String userConfirmPassword) {


    final ProgressDialog loading = ProgressDialog.show(this, "Registering", "Please wait...", false, false);
    loading.show();

    mAPIService.savePost(userPhone, userName, userEmail, userPassword, userConfirmPassword).enqueue(new Callback<LendingAppResponse>() {
        @Override
        public void onResponse(Response<LendingAppResponse> response, Retrofit retrofit) {
            if(response.body().getSuccess().equals("true")) {
                Intent intent = new Intent(SignUpActivity.this, ValidatePhone.class);
                intent.putExtra("phone", userPhone);
                startActivity(intent);
                loading.dismiss();
            }
            else {
                String message = response.body().getMessage();
                Toast.makeText(SignUpActivity.this, message, Toast.LENGTH_LONG).show();
                loading.dismiss();
            }
        }

        @Override
        public void onFailure(Throwable throwable) {
            String error = throwable.getMessage();
            Toast.makeText(SignUpActivity.this, throwable.getMessage() + " Please try again", Toast.LENGTH_SHORT).show();
            loading.dismiss();
        }
    });
}

I have searched but can't seem to find any good solution.

Upvotes: 0

Views: 878

Answers (1)

Gianluca Musa
Gianluca Musa

Reputation: 805

the solution: extending the time for timeout – by Lending Square

configuring a ReadTimeout and ConnectTimeout to to the httpClient an example:

   httpClient = new OkHttpClient();
   httpClient.setReadTimeout(60 * 1000, TimeUnit.MILLISECONDS);
   httpClient.setConnectTimeout(60 * 1000, TimeUnit.MILLISECONDS);

Upvotes: 1

Related Questions