sadegh saati
sadegh saati

Reputation: 1170

Android Retrofit encode URL

I'm using retrofit 2 and when I want to call a url like base/first/second slashes are converted into %2F According to retrofit official document I should be able to use

(@Path(value = "address" , encode = false)

but Android studio says : cannot find symbol method encode()

Upvotes: 4

Views: 9161

Answers (3)

J. Hill
J. Hill

Reputation: 515

What Emma said, but actually encoded=true not false.

Upvotes: 3

Caner Kaşeler
Caner Kaşeler

Reputation: 7538

Yes I had this problem from retrofit and I solved it with that:

Shortly, your answer is: (@Path(value ="address", encode = false) String address)

For example our link is: https://mobile.test/android

Firts off all, your Builder want to have an setEndpoint(). You can give "http:/" or "https:/" .

RestAdapter.Builder restBuilder = new RestAdapter.Builder()
            .setEndpoint("https://")
            .setConverter(new GsonConverter(gson))
            .setClient(new OkClient(new OkHttpClient()));
    return restBuilder.build();

Secondly, you should give your String value to @GET("/{address}"):

@GET("/{address}") void getExampleModels(@Path(value = "address", encode = false) String address, Callback<exampleModel> callback);

Finally, you can call it with String parameter without your error:

getYourClass().getExampleModels(
            "mobile.test/android",
            newCallback<exampleModel>(){ 
                . . . 
            });

Have a nice day.

Upvotes: 3

Emma
Emma

Reputation: 9363

Try -

encoded=false. Not encode=false

Upvotes: 6

Related Questions