Retrofit and GET using parameters

前端 未结 4 1301
时光取名叫无心
时光取名叫无心 2020-12-02 16:07

I am trying to send a request to the Google GeoCode API using Retrofit. The service interface looks like this:

public interface FooService {    
    @GET(\"         


        
4条回答
  •  悲&欢浪女
    2020-12-02 16:47

    I also wanted to clarify that if you have complex url parameters to build, you will need to build them manually. ie if your query is example.com/?latlng=-37,147, instead of providing the lat and lng values individually, you will need to build the latlng string externally, then provide it as a parameter, ie:

    public interface LocationService {    
        @GET("/example/")
        void getLocation(@Query(value="latlng", encoded=true) String latlng);
    }
    

    Note the encoded=true is necessary, otherwise retrofit will encode the comma in the string parameter. Usage:

    String latlng = location.getLatitude() + "," + location.getLongitude();
    service.getLocation(latlng);
    

提交回复
热议问题