簡體   English   中英

捕獲來自放心請求的響應的問題

[英]Problem with catching the response from rest-assured request

我正在使用 JAVA 和 REST-assured 庫來獲取來自 GET 請求的響應。 我希望從這個 URL 得到回復: https://www.samsung.comsmartphones/ (是的,在 .com 和智能手機之間沒有/)請找到我下面的代碼:

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

但在最后一行,它只是退出程序,沒有任何錯誤消息。 請幫我如何才能得到回應?

答案是:

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());
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM