Code example for HttpClient

Methods: execute, getConnectionManager

0
		 
		try { 
			List<NameValuePair> credentials = generateCredentialsForPost(username, password);
			HttpPost post = new HttpPost(WARMSHOWERS_USER_AUTHENTICATION_URL);
			post.setEntity(new UrlEncodedFormEntity(credentials));
			HttpResponse response = client.execute(post, httpContext);
 
			HttpEntity entity = response.getEntity();
			String rawJson = EntityUtils.toString(entity, "UTF-8");
            if (rawJson.contains("Already logged in")) {
                return 0; 
            } 
 
            JsonParser parser = new JsonParser();
            JsonObject o = (JsonObject) parser.parse(rawJson);
            String s = o.get("user").getAsJsonObject().get("uid").getAsString();
            userId = Integer.valueOf(s);
		} 
		 
		catch (ClientProtocolException e) {
			if (e.getCause() instanceof CircularRedirectException) {
				// If we getHost this authentication has still been successful, so ignore it 
			} else { 
				throw new HttpAuthenticationFailedException(e);
			} 
		}		 
		 
		catch (Exception e) {
			throw new HttpAuthenticationFailedException(e);
		} 
 
		finally { 
			client.getConnectionManager().shutdown();
		} 
 
		if (!isAuthenticated()) { 
			throw new HttpAuthenticationFailedException("Invalid credentials"); 
		}