码迷,mamicode.com
首页 > 编程语言 > 详细

Java 第三方库总结

时间:2015-08-11 21:08:14      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

1. OKHttp,好用的Http服务

官网地址:http://square.github.io/okhttp/

1) 获取http文件内容

 1 OkHttpClient client = new OkHttpClient();
 2 
 3 String run(String url) throws IOException {
 4   Request request = new Request.Builder()
 5       .url(url)
 6       .build();
 7 
 8   Response response = client.newCall(request).execute();
 9   return response.body().string();
10 }

2)发送POST请求

 1 public static final MediaType JSON
 2     = MediaType.parse("application/json; charset=utf-8");
 3 
 4 OkHttpClient client = new OkHttpClient();
 5 
 6 String post(String url, String json) throws IOException {
 7   RequestBody body = RequestBody.create(JSON, json);
 8   Request request = new Request.Builder()
 9       .url(url)
10       .post(body)
11       .build();
12   Response response = client.newCall(request).execute();
13   return response.body().string();
14 }

 

Java 第三方库总结

标签:

原文地址:http://www.cnblogs.com/zhouweihit/p/4722147.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!