Chait
Chait

Reputation: 677

In correct query string append to retrofit request in android

I am trying to pass "test+data" to Retrofit api call but during api request process it is processing as "test%2Bdata". Due to this my API request is failing.

How to pass exact text to retrofit call?

i am trying with below code.

build.gradle:

            buildConfigField("String", "api_type", "\"test+data\"")

Repository:

    apiService.getAllData(BuildConfig.api_type)).enqueue(object : Callback<User> {
    override fun onResponse(call: Call<User>, response: Response<User>) {
    }

    override fun onFailure(call: Call<User>, t: Throwable) {
       
    }
});

ApiService:

@GET("/?format=json")
fun getAllData(@Query("q") q: String) : Call<User>

Upvotes: 0

Views: 252

Answers (1)

Mustafa Dakhel
Mustafa Dakhel

Reputation: 188

You need to add 'encoded = true' to the @Query annotation, like this:

@Query("q" , encoded = true)

Upvotes: 1

Related Questions