java.io.EOFException: End of input at line 1 column 1 path $ in Android retrofit
Solution 1
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.
Solution 2
When I used Coroutines what helped me was not returning anything from function call:
@GET
@Headers("X-Requested-With:XMLHttpRequest")
suspend fun functionCall(
@Url url: String
)
Krzysztof Huminski
★ TOP RATED on Upwork Apart from the regular developers that focused in one field, I have rich experience in following areas and can provide you the optimized solutions that encompass both native and cross-platform mobile businesses. ★ Xamarin - Highly experienced with Xamarin.iOS & Xamarin.forms, Strong skills with Custom Renderer and Dependency Service ★ Web application development - AngularJS and Wordpress ★ iOS - Experienced with Objective C & Swift, Push Notification, Social Integration, GPS & Location Services, In-App Purchase. ★ Android - Video sharing, Photo editing, Custom Launcher, Google Map, Material theme UI development, In-App Billing ★ Hybrid application development - Strong skills with Cordova, Ionic, Meteor, Framework7 and ReactNative ★ AWS(DynamoDB, Amazon S3, Cognito), Parse, Quickblocks, Dropbox API for PHP, Javascript, Objective C/Swift and Android ★ AppStore & PlayStore submission - Submitted more than 30 apps on AppStore and PlayStore
Updated on June 27, 2022Comments
-
Krzysztof Huminski about 2 years
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.