Send POST Requests from Java
Using the GET request from Java is very easy. You just create a URL with
the request and then get an input stream:
InputStream is = new
URL("hi.iq/register?name=J.Doe&email=abuse@spamcop.com").getInputStream();
In most cases, servers that process POST requests won't reject your GET request. Still, sometimes you'll have to POST instead of GET, particularly when you upload a file. Wouldn't having a solution like the form from Example 2 be nice? The corresponding Java request could look like this:
InputStream serverInput = ClientHttpRequest.post(
new java.net.URL("hi.iq/register"),
new Object[] {
"name", "J.Doe",
"email", "abuse@spamcop.com",
"test.txt", new
File("C:\home\vp\tmp\test.txt")
});
Unfortunately, so far no such solution exists.
The Solution: ClientHttpRequest
If you search the Internet, you will find some partial or complicated solutions for using POST requests in Java. The best commercial solution probably is JScape's HTTP(S) component. Its well-designed API covers everything specified in HTTP (see RFC 2068). Other solutions are either too weird and complicated (see
Ronald Tschal