如何通过OkHttp将查询参数添加到HTTP GET请求? [英] How to add query parameters to a HTTP GET request by OkHttp?
问题描述
我正在使用最新的okhttp版本: okhttp-2.3.0.jar
如何在okhttp中向GET请求添加查询参数在java?
我发现
I am using the latest okhttp version: okhttp-2.3.0.jar
How to add query parameters to GET request in okhttp in java ?
I found a related question about android, but no answer here!
As mentioned in the other answer, okhttp v2.4 offers new functionality that does make this possible.
This is not possible with the current version of okhttp, there is no method provided that will handle this for you.
The next best thing is building an url string or an URL
object (found in java.net.URL
) with the query included yourself, and pass that to the request builder of okhttp.
As you can see, the Request.Builder can take either a String or an URL.
Examples on how to build an url can be found at What is the idiomatic way to compose a URL or URI in Java?
这篇关于如何通过OkHttp将查询参数添加到HTTP GET请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!