Code example for UrlEncodedFormEntity

0
		int userId = 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);
		} 
		 
Stop searching for code, let great code find you!  Add Codota to your java IDE