Add query params to a GET request in okhttp in Android

后端 未结 4 808
星月不相逢
星月不相逢 2021-01-12 00:56

Is there a way to add query params (?param1=val1¶m2=val2) to a GET request using okhttp in Android?

I am looking for an API and no

4条回答
  •  被撕碎了的回忆
    2021-01-12 01:06

    Use HttpUrl.

    Say you already have a String url ready, just want to append the queries:

    HttpUrl url = HttpUrl.parse("http://www.google.com/search").newBuilder()
       .addQueryParameter("q", "cat videos")
       .build();
    

    For the details about query parameters, see Vitaly's answer, or refer to the documentation.

提交回复
热议问题