How to send HTTP POST requests from a servlet to an external web service?

I use GWT RPC to communicate between the client and the servlet, but from the same servlet I need to send the XML data via the POST HTTP request to an external web service.

Basically, I send him some XML data, the web service processes it and returns some other XML data that I will use.

I tried using com.google.gwt.http.client.RequestBuilder , but I was getting an exception error ( java.lang.UnsatisfiedLinkError ). From what I read, this is because this class is a CLIENT class and therefore cannot be used in a servlet (server side).

What else can I use to create HTTP POST requests?

Thanks in advance.

(Since servlet is some kind of java byte code, instead of java translated into Javascript on the client, I can mainly use Java classes from JRE / JDK)

+3
source share
1 answer

Do NOT use any GWT classes in your servlet code!

why narrow the wide thing!

There are many APIs that you can use to send HTTP requests to external servers.

If you do not like external libraries, use java.net.URLConnection it is easy to use.

Or even you can use the simplest, Apache HTTPClient

+2
source

All Articles