如何使用字符串进行改造获取请求?

How to make retrofit get request with strings?

我需要在改造中提出一个 Get 请求,参数将 Strings 由 space 分隔。

例如:

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

当我们在浏览器中点击上面的URL会变成这样:

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

如何通过改造实现?我知道基本的并且能够成功地从改造中调用 Get 请求,但所有这些都包含一个字符串或类似的参数。

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

为了调用上述请求,我编写了以下代码:

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

在上面的代码中使用 space 传递字符串需要更改什么?

我没用过 retrofit 。这不是改造问题。因为它是一个 GET 请求,所以 URL 不能包含 space,它必须使用 +%20。在服务器端再次解码。

看这里http://www.ietf.org/rfc/rfc3986.txt

更多信息

Is a URL allowed to contain a space?