okhttp get 参数
时间: 2023-09-25 13:07:15 浏览: 109
在使用 OkHttp 发送 GET 请求时,你可以通过在 URL 上添加查询参数来传递参数。以下是一个示例:
```java
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;
public class Example {
public static void main(String[] args) {
OkHttpClient client = new OkHttpClient();
// 构建请求URL时添加查询参数
String url = "https://example.com/api?param1=value1¶m2=value2";
Request request = new Request.Builder()
.url(url)
.build();
try {
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
} catch (IOException e) {
e.printStackTrace();
}
}
}
```
在上述示例中,我们将查询参数添加到 URL 中,使用 `?` 分隔 URL 和查询参数,使用 `&` 分隔多个查询参数。你可以根据自己的需要设置参数的值。
阅读全文
相关推荐


















