If you want to do an HTTP Post with parameters and have it be sent with a content type of "x-www-form-urlencoded" then the way to do that in Apache HTTP Client 3 is...
HttpMethod method = new PostMethod(myUrl)
method.setParams(mp)
method.addParameter("user_name", username)
method.addParameter("password", password)
method.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
int responseCode = httpClient.executeMethod(method)
But Apache HTTP Client 4 introduced the UrlEncodedFormEntity object, so the new way of doing the same there is...
HttpPost post = new HttpPost(url);
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("user_name", username));
urlParameters.add(new BasicNameValuePair("password", password));;
post.setEntity(new UrlEncodedFormEntity(urlParameters));
HttpResponse response = client.execute(post);
What purpose does this UrlEncodedFormEntity object serve other than setting the content type to "x-www-form-urlencoded"?
The docs say it creates an "An entity composed of a list of url-encoded pairs", but can't that be done just by setting the content type?