简体   繁体   中英

Problem with catching the response from rest-assured request

I'm using JAVA and REST-assured library to get the response from GET request. I wish to get response from this URL: https://www.samsung.comsmartphones/ (yes, without / between .com and smartphones) Please find my below code:

String URL = "https://www.samsung.comsmartphones/";
RestAssured.baseURI = URL;
RequestSpecification httpRequest = RestAssured.given();
Response response = httpRequest.request(Method.GET, "/");

But on the last line it's just quiting from the program without any error message. Please, help me how can I catch a response?

The answer is:

try{
            String URL = "https://www.samsung.comsmartphones/";
            RestAssured.baseURI = URL;
            RequestSpecification httpRequest = RestAssured.given();
            Response response = httpRequest.request(Method.GET, "/");

            int statusCode = response.getStatusCode();
            System.out.println("Statuse code: "+statusCode);
            throw new UnknownHostException();
        }
        catch(UnknownHostException e){
            System.out.println("Exception is: "+ e.getMessage());
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM