Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit2 no key name on URL parameter

I'm using Retrofit2

I need to ask api with simply get looking like that http://1.1.1.1/get?key=value1&value2

How can I have query with only value? As value2 in above example? I've tried like here: Retrofit no key name on URL parameter

  • Retrofit change ? sign to %3F.
  • @Query("") will do something like this &=value2
  • @QueryMap("") with empty value will od something like this &value2=

Any ideas?

like image 422
Artur Latoszewski Avatar asked Jan 01 '26 10:01

Artur Latoszewski


2 Answers

In this kind of case you can directly call entire URL.

@GET()
Call<ResponseVO> test(@Url() String url);

And call

test("http://1.1.1.1/get?key=value1&value2")
like image 82
Pratik Popat Avatar answered Jan 05 '26 07:01

Pratik Popat


With the latest version of Retrofit2 @QueryName

@GET("http://1.1.1.1/get")
Call<Object> getYourData(@Query("key") String key, @QueryName String value);

When you call the method, each query name is appended to the URL. You can see the JavaDoc here: https://square.github.io/retrofit/2.x/retrofit/retrofit2/http/QueryName.html

like image 39
Shane Avatar answered Jan 05 '26 07:01

Shane



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!