okHttp官网
https://square.github.io/okhttp/
github地址:https://github.com/square/okhttp
okHttp maven依赖
进入页面后:
同时,在左上角还可以下载对应的jar包
okHttp 请求网页demo
点击Full souce可查看完整代码
import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import java.io.IOException; public class OkHttpTest { final OkHttpClient client = new OkHttpClient(); String run(String url) throws IOException { Request request = new Request.Builder() .url(url) .build(); try (Response response = client.newCall(request).execute()) { return response.body().string(); } } public static void main(String[] args) throws IOException { OkHttpTest example = new OkHttpTest(); String response = example.run("https://www.baidu.com"); System.out.println(response); } }