Java Code Examples for com.squareup.okhttp.ResponseBody#close()
The following examples show how to use
com.squareup.okhttp.ResponseBody#close() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZalyHttpClient.java From wind-im with Apache License 2.0 | 6 votes |
public byte[] get(String url) throws Exception { ResponseBody body = null; try { Request request = new Request.Builder().url(url).build(); Response response = httpClient.newCall(request).execute(); if (response.isSuccessful()) { body = response.body(); byte[] res = body.bytes(); return res; } else { logger.error("http get url={} error.{}", url, response.message()); } } finally { if (body != null) { body.close(); } } return null; }
Example 2
Source File: ZalyHttpClient.java From wind-im with Apache License 2.0 | 6 votes |
public byte[] postString(String url, String json) throws IOException { ResponseBody body = null; try { RequestBody postBody = RequestBody.create(JSON, json); Request request = new Request.Builder().url(url).post(postBody).build(); Response response = httpClient.newCall(request).execute(); if (response.isSuccessful()) { body = response.body(); byte[] res = body.bytes(); return res; } else { logger.error("http post error.{}", response.message()); } } finally { if (body != null) { body.close(); } } return null; }
Example 3
Source File: ZalyHttpClient.java From wind-im with Apache License 2.0 | 6 votes |
public byte[] postBytes(String url, byte[] bytes) throws IOException { ResponseBody body = null; try { RequestBody postBody = RequestBody.create(JSON, bytes); Request request = new Request.Builder().url(url).post(postBody).build(); Response response = httpClient.newCall(request).execute(); if (response.isSuccessful()) { body = response.body(); byte[] res = body.bytes(); return res; } else { logger.error("http post error.{}", response.message()); } } finally { if (body != null) { body.close(); } } return null; }
Example 4
Source File: ZalyHttpClient.java From openzaly with Apache License 2.0 | 6 votes |
public byte[] get(String url) throws Exception { ResponseBody body = null; try { Request request = new Request.Builder().url(url).build(); Response response = httpClient.newCall(request).execute(); if (response.isSuccessful()) { body = response.body(); byte[] res = body.bytes(); return res; } else { logger.error("http get url={} error.{}", url, response.message()); } } finally { if (body != null) { body.close(); } } return null; }
Example 5
Source File: ZalyHttpClient.java From openzaly with Apache License 2.0 | 6 votes |
public byte[] postString(String url, String json) throws IOException { ResponseBody body = null; try { RequestBody postBody = RequestBody.create(JSON, json); Request request = new Request.Builder().url(url).post(postBody).build(); Response response = httpClient.newCall(request).execute(); if (response.isSuccessful()) { body = response.body(); byte[] res = body.bytes(); return res; } else { logger.error("http post error.{}", response.message()); } } finally { if (body != null) { body.close(); } } return null; }
Example 6
Source File: ZalyHttpClient.java From openzaly with Apache License 2.0 | 6 votes |
public byte[] postBytes(String url, byte[] bytes) throws IOException { ResponseBody body = null; try { RequestBody postBody = RequestBody.create(JSON, bytes); Request request = new Request.Builder().url(url).post(postBody).build(); Response response = httpClient.newCall(request).execute(); if (response.isSuccessful()) { body = response.body(); byte[] res = body.bytes(); return res; } else { logger.error("http post error.{}", response.message()); } } finally { if (body != null) { body.close(); } } return null; }
Example 7
Source File: ZalyHttpClient.java From openzaly with Apache License 2.0 | 6 votes |
public byte[] get(String url) throws Exception { ResponseBody body = null; try { Request request = new Request.Builder().url(url).build(); Response response = httpClient.newCall(request).execute(); if (response.isSuccessful()) { body = response.body(); byte[] res = body.bytes(); return res; } else { logger.error("http get url={} error.{}", url, response.message()); } } finally { if (body != null) { body.close(); } } return null; }
Example 8
Source File: ZalyHttpClient.java From openzaly with Apache License 2.0 | 6 votes |
public byte[] postString(String url, String json) throws IOException { ResponseBody body = null; try { RequestBody postBody = RequestBody.create(JSON, json); Request request = new Request.Builder().url(url).post(postBody).build(); Response response = httpClient.newCall(request).execute(); if (response.isSuccessful()) { body = response.body(); byte[] res = body.bytes(); return res; } else { logger.error("http post error.{}", response.message()); } } finally { if (body != null) { body.close(); } } return null; }
Example 9
Source File: ZalyHttpClient.java From openzaly with Apache License 2.0 | 6 votes |
public byte[] postBytes(String url, byte[] bytes) throws IOException { ResponseBody body = null; try { RequestBody postBody = RequestBody.create(JSON, bytes); Request request = new Request.Builder().url(url).post(postBody).build(); Response response = httpClient.newCall(request).execute(); if (response.isSuccessful()) { body = response.body(); byte[] res = body.bytes(); return res; } else { logger.error("http post error.{}", response.message()); } } finally { if (body != null) { body.close(); } } return null; }
Example 10
Source File: NameFetcher.java From RedisBungee with Eclipse Public License 1.0 | 6 votes |
public static List<String> nameHistoryFromUuid(UUID uuid) throws IOException { String url = "https://api.mojang.com/user/profiles/" + uuid.toString().replace("-", "") + "/names"; Request request = new Request.Builder().url(url).get().build(); ResponseBody body = httpClient.newCall(request).execute().body(); String response = body.string(); body.close(); Type listType = new TypeToken<List<Name>>() { }.getType(); List<Name> names = RedisBungee.getGson().fromJson(response, listType); List<String> humanNames = new ArrayList<>(); for (Name name : names) { humanNames.add(name.name); } return humanNames; }