Last active
March 25, 2024 13:54
Revisions
-
akshaydashrath revised this gist
Apr 8, 2014 . 1 changed file with 13 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,15 @@ @Override public Response execute(Request request) throws IOException { HttpsURLConnection connection = (HttpsURLConnection) super.openConnection(request); try { prepareRequest(connection, request); } catch (Exception e) { e.printStackTrace(); } return readResponse(connection); } void prepareRequest(HttpURLConnection connection, Request request) throws IOException, OAuthExpectationFailedException, NoSuchAlgorithmException, OAuthCommunicationException, OAuthMessageSignerException { if (Build.VERSION.SDK_INT > 13) { @@ -26,4 +37,4 @@ void prepareRequest(HttpURLConnection connection, Request request) if (body!=null) { body.writeTo( connection.getOutputStream() ); } } -
akshaydashrath created this gist
Apr 8, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ void prepareRequest(HttpURLConnection connection, Request request) throws IOException, OAuthExpectationFailedException, NoSuchAlgorithmException, OAuthCommunicationException, OAuthMessageSignerException { if (Build.VERSION.SDK_INT > 13) { connection.setRequestProperty("Connection", "close"); } connection.setRequestMethod(request.getMethod()); connection.setDoInput(true); for (Header header : request.getHeaders()) { connection.addRequestProperty(header.getName(), header.getValue()); } TypedOutput body = request.getBody(); long length = -1; if (body != null) { connection.setDoOutput(true); length = body.length(); } RequestSigner.create(CONSUMER_KEY, CONSUMER_SECRET) .setOAuthTokenAndSecret(getToken(request), getoAuthSecret(request)) .sign(request, connection); if (length != -1) { connection.setFixedLengthStreamingMode((int) length); } else { connection.setChunkedStreamingMode(CHUNK_SIZE); } if (body!=null) { body.writeTo( connection.getOutputStream() ); } }