Java io eofexception retrofit

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

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 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 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

Читайте также:  Php pdo check if error

Comments

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.

 @FormUrlEncoded @POST("/ifapi.php") Call loadData(@Field("user") TransactionRequest user); 
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; >> 
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 meResponse = service.loadData(request); meResponse.enqueue(new Callback() < @Override public void onResponse(Callcall, Response response) < if (response.isSuccessful()) < TransactionResponse body = response.body(); Actions actions = body.getActions(); Mapparams = actions.getParams(); > > @Override public void onFailure(Call call, Throwable t) < t.printStackTrace(); >>); 
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' 

enter image description here

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

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.io.EOFException: End of input at line 1 column 1 path $ #3229

java.io.EOFException: End of input at line 1 column 1 path $ #3229

Comments

I launch this request with retrofit_version = ‘2.6.2’
My data actually get saved on my Server (API) Side but I still get this error

E/AndroidRuntime: FATAL EXCEPTION: main
Process: za.co.zone.marketingapp, PID: 27127
java.io.EOFException: End of input at line 1 column 1 path $
at com.google.gson.stream.JsonReader.nextNonWhitespace(JsonReader.java:1397)
at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:550)
at com.google.gson.stream.JsonReader.peek(JsonReader.java:426)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:207)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:39)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:27)
at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:225)
at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:121)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:206)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
I/Process: Sending signal. PID: 27127 SIG: 9
Process 27127 terminated.

The text was updated successfully, but these errors were encountered:

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.io.EOFException: End of input at line 1 column 1 path $ #3229

java.io.EOFException: End of input at line 1 column 1 path $ #3229

Comments

I launch this request with retrofit_version = ‘2.6.2’
My data actually get saved on my Server (API) Side but I still get this error

E/AndroidRuntime: FATAL EXCEPTION: main
Process: za.co.zone.marketingapp, PID: 27127
java.io.EOFException: End of input at line 1 column 1 path $
at com.google.gson.stream.JsonReader.nextNonWhitespace(JsonReader.java:1397)
at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:550)
at com.google.gson.stream.JsonReader.peek(JsonReader.java:426)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:207)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:39)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:27)
at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:225)
at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:121)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:206)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
I/Process: Sending signal. PID: 27127 SIG: 9
Process 27127 terminated.

The text was updated successfully, but these errors were encountered:

Источник

Оцените статью