public class RESTClient extends Object
RESTClient client = new RESTClient();
String json = "{["example1", "example2"]}";
String result = client.send_request("http://localhost:8080/myWebService/method", json, "application/json", "POST", null, null);
Example of usage of DELETE:
RESTClient client = new RESTClient();
client.send_request(urlSec+"?ID=12", "DELETE", username, password);
Example of usage of GET:
RESTClient client = new RESTClient();
client.send_request(urlSec+"?username=fabrizio.celli", "GET", username, password);
Constructor and Description |
---|
RESTClient() |
Modifier and Type | Method and Description |
---|---|
String |
send_request(String url,
String method,
String username,
String password)
Method to send a GET or DELETE request to a RESTful web service.
|
String |
send_request(String url,
String payload,
String contentType,
String method,
String username,
String password)
Method to send a POST or PUT request to a RESTful web service.
|
public String send_request(String url, String payload, String contentType, String method, String username, String password) throws IOException
url
- the URL of the web servicepayload
- the content of this requestcontentType
- the content type of the payload (e.g. application/json)method
- POST or PUTusername
- (optional) in case of authentication, can be nullpassword
- (optional) in case of authentication, can be null. This password is encoded using Base64.IOException
- IOExceptionpublic String send_request(String url, String method, String username, String password) throws IOException
url
- the URL of the web servicemethod
- GET or DELETEusername
- (optional) in case of authentication, can be nullpassword
- (optional) in case of authentication, can be null. This password is encoded using Base64.IOException
- IOExceptionCopyright © 2016. All rights reserved.