Question: I need a simple code example of sending http post request with post parameters that I get from form inputs. 
I have found Apache HTTPClient, it has very reach API and lots of sophisticated examples, but I couldn't find a simple example of sending http post request with input parameters and getting text response.

**Update:** I'm interested in Apache HTTPClient v.4.x, as 3.x is deprecated.

Answer: 
Here's the sample code for Http POST, using Apache HTTPClient API.

```
import java.io.InputStream;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;

public class PostExample {
    public static void main(String[] args){
        String url = "http://www.google.com";
        InputStream in = null;

        try {
            HttpClient client = new HttpClient();
            PostMethod method = new PostMethod(url);

            //Add any parameter if u want to send it with Post req.
            method.addParameter("p", "apple");

            int statusCode = client.executeMethod(method);

            if (statusCode != -1) {
                in = method.getResponseBodyAsStream();
            }

            System.out.println(in);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

```
<http://httpunit.sourceforge.net/doc/cookbook.html>
use PostMethodWebRequest and setParameter method