public class HttpRequestUtil extends Object
| Constructor and Description |
|---|
HttpRequestUtil() |
| Modifier and Type | Method and Description |
|---|---|
static HttpResponse |
doGet(String endpoint,
Map<String,String> headers) |
static HttpResponse |
doPost(URL endpoint,
String body) |
static HttpResponse |
doPost(URL endpoint,
String postBody,
Map<String,String> headers) |
static HttpResponse |
sendGetRequest(String endpoint,
String requestParameters)
Sends an HTTP GET request to a url
|
static void |
sendPostRequest(Reader data,
URL endpoint,
Writer output)
Reads data from the data reader and posts it to a server via POST request.
|
static void |
sendPostRequest(Reader data,
URL endpoint,
Writer output,
String contentType)
Reads data from the data reader and posts it to a server via POST request.
|
static void |
sendPutRequest(Reader data,
URL endpoint,
Writer output,
String contentType)
Reads data from the data reader and posts it to a server via PUT request.
|
public static HttpResponse sendGetRequest(String endpoint, String requestParameters) throws IOException
endpoint - - The URL of the server. (Example: " http://www.yahoo.com/search")requestParameters - - all the request parameters (Example: "param1=val1¶m2=val2").
Note: This method will add the question mark (?) to the request - DO NOT add it yourselfIOException - If an error occurs while sending the GET requestpublic static void sendPostRequest(Reader data, URL endpoint, Writer output) throws Exception
data - Data to be sentendpoint - The endpoint to which the data has to be POSTedoutput - OutputException - If an error occurs while POSTingpublic static HttpResponse doPost(URL endpoint, String body) throws Exception
Exceptionpublic static HttpResponse doPost(URL endpoint, String postBody, Map<String,String> headers) throws Exception
Exceptionpublic static HttpResponse doGet(String endpoint, Map<String,String> headers) throws IOException
IOExceptionpublic static void sendPostRequest(Reader data, URL endpoint, Writer output, String contentType) throws Exception
data - Data to be sentendpoint - The endpoint to which the data has to be POSTedoutput - OutputcontentType - content type of the messageException - If an error occurs while POSTingpublic static void sendPutRequest(Reader data, URL endpoint, Writer output, String contentType) throws Exception
data - Data to be sentendpoint - The endpoint to which the data has to be POSTedoutput - OutputcontentType - content type of the messageException - If an error occurs while POSTingCopyright © 2014. All rights reserved.