Vikas singh
Vikas singh

Reputation: 3889

How to parse parameters using get method with Retrofit?

I want to pass 2 parameters and get data through Retrofit However i am getting following Response in log.

code...404 message...Not Found body...null

Here below following code what i am trying..

This is my interface

public interface RequestInterface { 
    String NOTIFICATION_URL = "http://xxxxx/api/";  
    @GET("Image/GetNotificationList/{PageNumber}/{PageSize}")
    Call<List<GetNotification>> getNotification(@Path("PageNumber")  String PageNumber, @Path("PageSize") String PageSize); 
}

When i call the RequestInterface

private void notificationJSON() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(RequestInterface.NOTIFICATION_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        RequestInterface request = retrofit.create(RequestInterface.class);
        Call<List<GetNotification>> call = request.getNotification("1","10");

        call.enqueue(new Callback<List<GetNotification>>() {
            @Override
            public void onResponse(Call<List<GetNotification>> call, Response<List<GetNotification>> response) {
                List<GetNotification> notification_pojo = response.body();
                Log.d("Message", "code..."+response.code() + " message..." + response.message()+" body..."+response.body());
                Log.d("Message pojo", "notification_pojo = " +notification_pojo);
            }

            @Override
            public void onFailure(Call<List<GetNotification>> call, Throwable t) {
                Log.e("onFailure ", t.getMessage());
            }
        });

Here is my Api Response

[  
   {  
      "PageUrl":"ureeee",
      "CircularDetailId":1,
      "Subject":"suBJECT",
      "CircularPath":"/UploadDocument/3phasehindi.pdf",
      "Description":"Description"
   },
   ......
]

Api working Screenshot

enter image description here

Upvotes: 0

Views: 1443

Answers (2)

Faizan Mubasher
Faizan Mubasher

Reputation: 4569

This is working for me:

public interface RequestInterface { 
String NOTIFICATION_URL = "http://xxxxx/api/";  
@GET("Image/GetNotificationList")
Call<List<GetNotification>> getNotification(@Query("PageNumber")  String PageNumber, @Query("PageSize") String PageSize); 
}

GetNotification.java

public class GetNotification{

  @SerializedName("PageUrl")
  @Expose
  private String pageUrl;
  @SerializedName("CircularDetailId")
  @Expose
  private Integer circularDetailId;
  @SerializedName("Subject")
  @Expose
  private String subject;
  @SerializedName("CircularPath")
  @Expose
  private String circularPath;
  @SerializedName("Description")
  @Expose
  private String description;

  public String getPageUrl() {
     return pageUrl;
  }

  public void setPageUrl(String pageUrl) {
      this.pageUrl = pageUrl;
  }

  public Integer getCircularDetailId() {
      return circularDetailId;
  }

  public void setCircularDetailId(Integer circularDetailId) {
    this.circularDetailId = circularDetailId;
  }

  public String getSubject() {
    return subject;
  }

  public void setSubject(String subject) {
     this.subject = subject;
  }

  public String getCircularPath() {
     return circularPath;
  }

  public void setCircularPath(String circularPath) {
       this.circularPath = circularPath;
  }

  public String getDescription() {
       return description;
  }

  public void setDescription(String description) {
      this.description = description;
  }
} 

Upvotes: 0

Ramesh sambu
Ramesh sambu

Reputation: 3539

Try this your using query params change instead of Path

 public interface RequestInterface { 

 String NOTIFICATION_URL = "http://xxxxx/api/";  

 @GET("Image/GetNotificationList")
 Call<List<GetNotification>> getNotification(@Query("PageNumber")  String 
     PageNumber, @Query("PageSize") String PageSize); 

 }

Upvotes: 1

Related Questions