SARATH V
SARATH V

Reputation: 500

Retrofit gives null response while calling Post request from android

Current response

Response{protocol=http/1.0, code=404, message=Not Found, 
    url=http://testapp*****/api/dev/myapp**/subscription%2F2be110}

But url which i'm passing is

url=http://testapp*****/api/dev/myapp**/subscription/2be110

"subscription/2be110" which is passing as string to api service which receives at following function

@Headers("Content-Type: application/json;charset=UTF-8","Accept: application/json")
    @POST("{urlEndString}")
    fun getResponse(
        @Path ("urlEndString") urlEndString : String, @Body `object`: JsonObject
    ):Call<JsonObject>

How back slash changed to "%2F" format ? Any solution to resolve this issue?

Nb: using retrofit2

Upvotes: 0

Views: 199

Answers (1)

Vladyslav Matviienko
Vladyslav Matviienko

Reputation: 10871

@Path parameters are URLEncoded. Therefore slash will be URLEncoded as well. You can use 2 path parameters like

@POST("{urlEndString1}/{urlEndString2}")
fun getResponse(
        @Path ("urlEndString1") urlEndString1 : String, @Path ("urlEndString2") urlEndString2 : String, @Body `object`: JsonObject):Call<JsonObject>

And pass 2 parts of your URL ending split by slash.

As alternative, you can use @Path(value="urlEndString", encoded=true) to show that the parameter is already encoded, and Retrofit does not need to encode it.

Upvotes: 1

Related Questions