That particular error you’re getting is because that is, in fact, an invalid HTTP 1.1 request. I strongly recommend using a tested client API instead of trying to do HTTP yourself, like
URL.openConnection() or the
Jakarta Commons HttpClient.
There is a quite a lot to do to implement HTTP 1.1 POST correctly, like including the correct Host, Connection, Date, Content-Type and Content-Length headers, encoding the query parameters, handling chunked encoding in replies that the one you included, etc. The
HttpClient PostMethod will do all this for you.