Questions Questions - 1 year ago 138
Java Question

RESTful call in Java

I am going to make a RESTful call in Java. However, I don't know how to make the call. Do I need to use the URLConnection or others? Can anyone help me. thank you.

Answer Source

If you are calling a RESTful service from a Service Provider (e.g Facebook, Twitter), you can do it with any flavour of your choice:

If you don't want to use external libraries, you can use or (for SSL), but that is call encapsulated in a Factory type pattern in To receive the result, you will have to connection.getInputStream() which returns you an InputStream. You will then have to convert your input stream to string and parse the string into it's representative object (e.g. XML, JSON, etc).

Alternatively, Apache HttpClient (version 4 is the latest). It's more stable and robust than java's default URLConnection and it supports most (if not all) HTTP protocol (as well as it can be set to Strict mode). Your response will still be in InputStream and you can use it as mentioned above.

Documentation on HttpClient:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download