List of usage examples for com.squareup.okhttp Response Response
private Response(Builder builder)
From source file:com.frostwire.http.HttpClient.java
License:Open Source License
public void send(final Request request, final RequestListener listener) { c.newCall(buildReq(request)).enqueue(new Callback() { @Override/*from ww w.j a v a 2s . c o m*/ public void onFailure(com.squareup.okhttp.Request r, IOException e) { try { listener.onFailure(request, e); } catch (Throwable t) { LOG.warn("Error invoking listener", t); } } @Override public void onResponse(com.squareup.okhttp.Response r) throws IOException { try { if (r != null) { listener.onResponse(new Response(r)); } else { listener.onFailure(request, new IOException("response is null, review internal okhttp framework.")); } } catch (Throwable t) { LOG.warn("Error invoking listener", t); } finally { IOUtils.closeQuietly(r.body()); } } }); }
From source file:com.horntell.http.Request.java
Response doGetRequest(String url) throws IOException { String credential = Credentials.basic(App.getKey(), App.getSecret()); com.squareup.okhttp.Request request = new com.squareup.okhttp.Request.Builder().url(url) .header("Authorization", credential) .addHeader("Accept", "application/vnd.horntell." + App.getVersion() + "+json") .addHeader("Content-Type", "text/json").build(); com.squareup.okhttp.Response response = client.newCall(request).execute(); return new Response(response); }
From source file:com.horntell.http.Request.java
private Response doPostRequest(String url, Map<String, Object> params) throws IOException { String credential = Credentials.basic(App.getKey(), App.getSecret()); String json = new JSONObject(params).toString(); RequestBody body = RequestBody.create(JSON, json); com.squareup.okhttp.Request request; request = new com.squareup.okhttp.Request.Builder().url(url).header("Authorization", credential) .addHeader("Accept", "application/vnd.horntell." + App.getVersion() + "+json") .addHeader("Content-Type", "text/json").post(body).build(); com.squareup.okhttp.Response response = client.newCall(request).execute(); return new Response(response); }
From source file:com.horntell.http.Request.java
private Response doDeleteRequest(String url) throws IOException { String credential = Credentials.basic(App.getKey(), App.getSecret()); com.squareup.okhttp.Request request; request = new com.squareup.okhttp.Request.Builder().url(url).header("Authorization", credential) .addHeader("Accept", "application/vnd.horntell." + App.getVersion() + "+json") .addHeader("Content-Type", "text/json").delete().build(); com.squareup.okhttp.Response response = client.newCall(request).execute(); return new Response(response); }
From source file:com.horntell.http.Request.java
private Response doPutRequest(String url, Map<String, Object> params) throws IOException { String credential = Credentials.basic(App.getKey(), App.getSecret()); String json = new JSONObject(params).toString(); RequestBody body = RequestBody.create(JSON, json); com.squareup.okhttp.Request request; request = new com.squareup.okhttp.Request.Builder().url(url).header("Authorization", credential) .addHeader("Accept", "application/vnd.horntell." + App.getVersion() + "+json") .addHeader("Content-Type", "text/json").put(body).build(); com.squareup.okhttp.Response response = client.newCall(request).execute(); return new Response(response); }