Code example for HttpURLConnection

Methods: getInputStream, getOutputStream, setDoOutput

0
    private void 
    performFetch(Handler callingThread)
    { 
        try { 
        	// Post the credentials. 
    		connection.setDoOutput(true); 
            OutputStream out = connection.getOutputStream(); 
            out.write(postData); 
            out.close(); 
            // Wait for the response.   
            // Note that getInputStream will throw exception for non-200 status. 
            InputStream response = connection.getInputStream(); 
            byte[] data = readAllBytes(response); 
            // Extract the token from JSON. 
			String body = new String(data, "UTF8"); 
			JSONObject json = new JSONObject(body); 
			final String token = json.getString("access_token"); 
            // Give it back to the client. 
            callingThread.post(new Runnable() { 
                public void run() { 
                    if (client != null)