Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.io.EOFException: End of input at line 1 column 1 path $ in Android retrofit

I'm using Retrofit to consume a REST API endpoint, and I'm having the following issue. I think the something is wrong with data model on TransactionResponse class, but not sure yet.

java.io.EOFException: End of input at line 1 column 1 path $ in Android retrofit

My call request is as follows.

 @FormUrlEncoded
@POST("/ifapi.php")
Call<TransactionResponse> loadData(@Field("user") TransactionRequest user);

TransactionRequest class :

import javax.annotation.Generated;

@Generated("org.jsonschema2pojo")

public class TransactionResponse {

    private Settings settings;
    /**
     *
     * @return
     * The settings
     */

    public Settings getSettings()
    {
        return settings;
    }
    /**
     *
     * @param settings
     * The settings
     */

    public void setSettings(Settings settings)
    {
        this.settings = settings;
    }

    private Actions actions;
    /**
     *
     * @return
     * The actions
     */
    public Actions getActions()
    {
        return actions;
    }
    /**
     *
     * @param actions
     * The actions
     */
    public void setActions(Actions actions)
    {
        this.actions = actions;
    }
}

And below is the code where call is actually done.

OkHttpClient httpClient = new OkHttpClient.Builder().build();
Retrofit retrofit = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create()).baseUrl( 
RestAPI.BASE_URL).client(httpClient).build();
RestAPI service = retrofit.create(RestAPI.class);
Call<TransactionResponse> meResponse = service.loadData(request);

meResponse.enqueue(new Callback<TransactionResponse>() {
       @Override 
       public void onResponse(Call<TransactionResponse> call, Response<TransactionResponse> response) {
               if (response.isSuccessful()) {
                       TransactionResponse body = response.body();
                       Actions actions = body.getActions();
                       Map<String, String> params = actions.getParams();
               }
       }

       @Override
       public void onFailure(Call<TransactionResponse> call, Throwable t){
              t.printStackTrace();
       }
  });

Can anyone please help me? Thanks in advance.

I'm using the following libraries.

compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'javax.annotation:javax.annotation-api:1.2'
compile 'com.squareup.retrofit2:converter-gson:2.2.0'

P.S I found that the request worked with form data, but not with JSON data. enter image description here

like image 655
Krzysztof Huminski Avatar asked Sep 02 '25 17:09

Krzysztof Huminski


1 Answers

I have found the solution, you need to post each parameters in the form as follows, not in a wrapper class.

@FormUrlEncoded

@POST("/ifapi.php")

Call<TransactionResponse> loadData(@Field("app_id") String app_id, @Field("install_id") String install_id, @Field("useragent") String useragent, @Field("ip") String ip, @Field("mccmnc") String mccmnc, @Field("action") String action );

And for main Activity Part.

OkHttpClient httpClient = new OkHttpClient.Builder().build();
Gson gson = new GsonBuilder()
                                       .setLenient()
                                       .create();
Retrofit retrofit = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create(gson)).baseUrl(RestAPI.BASE_URL).client(httpClient).build();

RestAPI service = retrofit.create(RestAPI.class);
Call<TransactionResponse> meResponse = service.loadData("1", getUUID(), getUserAgent(), getIPAddress(), "20404", "start");

Hope this will resolve your issues, Regards.

like image 143
Shiny_pro Avatar answered Sep 04 '25 07:09

Shiny_pro