Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GET request in URL that has params appended by `&` using Retrofit

How to make HTTP GET request in URL that has params appended by & using Retrofit in Android?

URL: http://api.com?name=remote&class=TV

Currently, i am using:

@GET("http://api.com?name={name}&class={class}")
    Call<CustomType> get(
            @Path(value = "name",encoded = false) String name,
            @Path(value = "class",encoded = false) String class);

I am getting following error:

java.lang.IllegalArgumentException: URL query string "name={name}&class={class}" 
must not have replace block. 
For dynamic query parameters use @Query.
like image 320
Malwinder Singh Avatar asked Mar 24 '16 04:03

Malwinder Singh


1 Answers

It's a standard GET request url. Just use @Query:

@GET("http://api.com")
Call<CustomType> get(
        @Query("name") String name,
        @Query("class") String classs);

It will access url: http://api.com?name=remote&class=TV

like image 153
rafakob Avatar answered Oct 11 '22 23:10

rafakob