如何从头开始发出 HTTP 请求的基础知识,可用于 Oauth 和不同的 api 调用



有像Retrofit这样的框架,但我想学习基础知识,有很多可用的类,它令人困惑,如果有的话,请提及一些参考资料。

Retrofit 默认使用 OkHttp。

我个人包括对依赖项implementation 'com.squareup.okhttp3:okhttp:3.7.0

我这样使用它:

private Response post(String url, String body) throws IOException {
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), body);
Request request = new Request.Builder().url(url).post(requestBody).build();
return <yourOkHttpClient>.newCall(request).execute();
}

您有几个教程介绍如何在搜索时发出所需的请求。

你还有其他更健壮的框架,比如最近支持的 Volley b Google,你可以使用它。

最新更新