Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()

like image 795
sadegh saati Avatar asked Mar 13 '23 23:03

sadegh saati


2 Answers

Try -

encoded=false. Not encode=false

like image 89
Emma Avatar answered Mar 28 '23 03:03

Emma


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.

like image 29
DevPolarBear Avatar answered Mar 28 '23 02:03

DevPolarBear