A URLConnection for an http URL will set up the request
line and the MIME header for you as long as you
set its doOutput field to true by
invoking setDoOutput(true).
If you also want to read from the connection, you
should set doInput to true with setDoInput(true) too.
For example,
URLConnection uc = u.openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
The request line and MIME header are sent as soon as the URLConnection connects.
Then getOutputStream() returns an output stream
on which you can write the x-www-form-urlencoded name-value pairs.