Class HttpRequestUtil


  • public class HttpRequestUtil
    extends Object
    A utility for handling HTTP requests
    • Constructor Detail

      • HttpRequestUtil

        public HttpRequestUtil()
    • Method Detail

      • sendGetRequest

        public static org.wso2.carbon.automation.test.utils.http.client.HttpResponse sendGetRequest​(String endpoint,
                                                                                                    String requestParameters)
                                                                                             throws IOException
        Sends an HTTP GET request to a url
        Parameters:
        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 yourself
        Returns:
        - The response from the end point
        Throws:
        IOException - If an error occurs while sending the GET request
      • sendPostRequest

        public static void sendPostRequest​(Reader data,
                                           URL endpoint,
                                           Writer output)
                                    throws Exception
        Reads data from the data reader and posts it to a server via POST request. data - The data you want to send endpoint - The server's address output - writes the server's response to output
        Parameters:
        data - Data to be sent
        endpoint - The endpoint to which the data has to be POSTed
        output - Output
        Throws:
        Exception - If an error occurs while POSTing
      • doPut

        public static org.wso2.carbon.automation.test.utils.http.client.HttpResponse doPut​(URL endpoint,
                                                                                           String putBody,
                                                                                           Map<String,​String> headers)
                                                                                    throws Exception
        Parameters:
        endpoint -
        putBody -
        headers -
        Returns:
        Throws:
        Exception
      • doDelete

        public static int doDelete​(URL endpoint,
                                   Map<String,​String> headers)
                            throws Exception
        Send
        Parameters:
        endpoint - - The URL of the server. (Example: " http://www.yahoo.com/search")
        headers - -
        Returns:
        - The response code from the endpoint
        Throws:
        Exception - - ava.io.IOException If an error occurs while sending the DELETE request