简体   繁体   中英

Basics of how to make HTTP request from ground up which can be use for Oauth and diiferent api calls

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

Retrofit uses OkHttp as default.

I personally include implementation 'com.squareup.okhttp3:okhttp:3.7.0 on dependencies

and I use it this way:

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();
}

You have several tutorials on how to make the requests you want if you search for it.

You also have other, more robust frameworks, like Volley that is recently supported b Google, which you can use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM