设为首页 加入收藏

TOP

github认证登陆(三)
2019-09-30 16:48:15 】 浏览:85
Tags:github 认证 登陆
quot;, "updated_at": "2017-05-06T08:16:22Z" }

 

授权之后,每次登陆都不需要再次授权,可更换浏览器或者选择revoke all user tokens 就可以了!

okhttpclient的用例与介绍

介绍

OkHttp是一个HTTP客户机,默认情况下是高效的:

  • http/2支持允许对同一主机的所有请求共享套接字。

  • 连接池可以减少请求延迟(如果HTTP/2不可用)。

  • 透明GZIP缩小下载大小。

  • 响应缓存完全避免了重复请求的网络。

     

 OkHttpClient client = new OkHttpClient();
 //获取URL
 //访问URL并获取该网站返回过来的字符串
 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 final MediaType JSON
     = MediaType.get("application/json; charset=utf-8");
 ?
 OkHttpClient client = new OkHttpClient();
 //发送到服务器
 //通过build一个request 并将需要的参数封装到body 访问url,执行client.newCall(request).execute(),得到返回值,一般是一个json格式的字符串,当然也可以自己选择它的返回数据格式!
 String post(String url, String json) throws IOException {
   RequestBody body = RequestBody.create(json, JSON);
   Request request = new Request.Builder()
       .url(url)
       .post(body)
       .build();
   try (Response response = client.newCall(request).execute()) {
     return response.body().string();
   }
 }

 

详情参见:okhttp

githubdeveloper手册

首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Java细节----method和function的.. 下一篇github认证登陆

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目