0

I need to make a Get request in retrofit and the parameter would be Strings separated by space.

For example:

http://www.something.com?req=hello testing

When we hit the above URL in browser it will become like this:

http://www.something.com/?req=hello%20testing

How can I achieve with retrofit? I know the basic and able to call the Get request from retrofit successfully but all of those contain one string or similar parameters.

 @GET("/search?req={req}")
public Observable<List<Model>> getWarehouse (String req);

To call above request I wrote following code:

adapter.create(WarehouseAPI.class).getWarehouse()
            .subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Observer<List<Warehouse>>(){
    ..........
    ..........

What do I need to change for passing string with spaces in above code?

pt2121
  • 11,720
  • 8
  • 52
  • 69

1 Answers1

0

I haven't used retrofit . It's not a retrofit issue. Since it's a GET request, a URL must not contain a space, it must be encoded either using + or %20. Which is again decoded on the server side.

Have a look here http://www.ietf.org/rfc/rfc3986.txt

For more info

Is a URL allowed to contain a space?

Community
  • 1
  • 1
Ritt
  • 3,181
  • 3
  • 22
  • 51