AMAN SINGH AMAN SINGH - 6 months ago 297
Android Question

Retrofit : Getting error ** End of input at line 1 column 1**

I don't know where my problem is. I've to post raw body like

{"app_id":"abced","app_key":"abced","request":"login","username":"abce@gmail.com","password":"1234"}


I'm using retrofit 2.0. I created a interface like

@FormUrlEncoded
@POST("index.php/")
Call<LoginResponse> getHome(@Field("app_id") String request,
@Field("app_key") String request1,
@Field("request") String request2,
@Field("username") String request3,
@Field("password") String request4);


and calling like this:

Retrofit retrofitget = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
MyAPI ApiData = retrofitget.create(MyAPI.class);
Call<LoginResponse> GalleryGetSet = ApiData.getHome("abced","abced","login","abce@gmail.com","1234");
GalleryGetSet.enqueue(new Callback<LoginResponse>() {
@Override
public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {
Log.e(TAG, "data1" + response.body().getError());
}

@Override
public void onFailure(Call<LoginResponse> call, Throwable t) {
Log.e(TAG, "Error2" + t.getMessage());
}
});


always getting error : End of input at line 1 column 1
Is it right process to post the raw body data through retrofit post or i'm wrong. Already google it but not got my solution.
Please anyone help me out.

I also tried in this way
in interface

@FormUrlEncoded
@POST("index.php")
Call<LoginResponse> getHome1(@Field("login") String data);


and while calling

Retrofit retrofitget = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(ScalarsConverterFactory.create())
.build();
MyAPI ApiData = retrofitget.create(MyAPI.class);

Call<LoginResponse> listGalleryGetSet = ApiData.getHome("ABCD","ABCD","login","ABC@gmail.com","1234");
listGalleryGetSet.enqueue(new Callback<LoginResponse>() {
@Override
public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {
Log.e(TAG, "data1" + response.body().getError());
}

@Override
public void onFailure(Call<LoginResponse> call, Throwable t) {
Log.e(TAG, "Error" + t.getMessage());
}
});


My LoginResponse class

public class LoginResponse {

private String error;

private Boolean vlink;

/**
*
* @return
* The error
*/
public String getError() {
return error;
}

/**
*
* @param error
* The error
*/
public void setError(String error) {
this.error = error;
}

/**
*
* @return
* The vlink
*/
public Boolean getVlink() {
return vlink;
}

/**
*
* @param vlink
* The vlink
*/
public void setVlink(Boolean vlink) {
this.vlink = vlink;
}


}

**This is how I'm posting on postman**

Thanks in advance

Answer

Instead of using

@POST("index.php")

please try to use

@POST("/index.php")

and post as a

Call<LoginResponse> getHome(@Body YourBodyPojo pojo);

surely this will help you.