asanchezyu
asanchezyu

Reputation: 700

Retrofit with special chars at url

In my current project, I have some issues about the " and "=" symbols at URL.

http://mysampledomain.com/login?q='userlogin'="sample"

I have tried everything. "@Path" doesn't work and when I try "@Query" the characters "=" and ' " ' are changed to ASCII and It doesn't work.

http://mysampledomain.com/login?q%3D%userlogin%27=%22sample%22

How could I make this kind of requests?

Thank you!

Upvotes: 3

Views: 3096

Answers (4)

Rudy
Rudy

Reputation: 158

Normally parameters through url are passed in different manner. In your case it would be:

http://mysampledomain.com/login?userlogin=sample&otherVariable=otherValue

Without ' ' characters usually.

For example I use node.js so it would be like:

app.get('/login', function(req, res) {
 var userLogin = req.query.userLogin;
 var otherVariable = req.query.otherVariable;

 // Do whatever you want.
});

Upvotes: 2

asanchezyu
asanchezyu

Reputation: 700

I found the solution.

for anyone that it could help, I have used the @Url annotation like this:

@GET
Call<ApiResponseModel> getUserDetails(@Header("Authorization") String token, @Url String fullUrl);

Thanks for all the people that have reply my question :)

Upvotes: 5

rana_sadam
rana_sadam

Reputation: 1226

Use this approach

public static final String BASE_URL + "http://mysampledomain.com/";

public interface RetrofitClient{

     @GET("login")
     Call<String> login(@QueryMap Map<String, String> map);

}

to call this

Map<String, String> map = new HashMap<>();
map.put("userlogin", "sample");
map.put("param2", "param2");

OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();

Gson gson = new GsonBuilder()
    .setLenient()
    .create();

Retrofit  r = new Retrofit.Builder()
       .baseUrl(BASE_URL)
       .addConverterFactory(ScalarsConverterFactory.create())
       .addConverterFactory(GsonConverterFactory.create(gson))
       .client(okBuilder.build())
       .build();

r.create(RetrofitClient.class).login(map).enqueue(this);

Upvotes: 1

Yogesh Mane
Yogesh Mane

Reputation: 591

Check your api url if your api like

http://mysampledomain.com/login?userlogin=sample&otherVariable=otherValue

then

  @GET("login")
  Observable<LoginResponse> getUserProductViewed(@Query("userlogin") String userlogin,@Query("otherVariable")String otherVariable);

and Base URL like :

public static String BASE_URL = "http://mysampledomain.com/";

Upvotes: -1

Related Questions