I have the following code in Perl which posts to my HTTP Servlet, calling an API with some XML data.
my $my_hash = {
'env.adapterName' => "DefaultAdapter",
'env.systemName' => "DefaultSystem",
'env.userId' => "admin",
'env.progId' => "PerlHttpTest",
InteropApiName => $apiName,
InteropApiData => $xmlData
};
my $res = $ua->request(POST 'http://hostname/interop/InteropHttpServlet', $my_hash);
I would like to do this in Java but I am struggling. Could someone please point me in the right direction? I want to post data to my servlet as above and get the response back (it will be XML).
The standard Java SE API offers you the
java.net.URLConnectionto fire and handle HTTP requests.There exist 3rd party API’s which makes this all little easier, like Apache HttpComponents Client.
See also: