Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法从网络日志中获取HTTP响应正文-Selenium_Selenium_Selenium Chromedriver - Fatal编程技术网

无法从网络日志中获取HTTP响应正文-Selenium

无法从网络日志中获取HTTP响应正文-Selenium,selenium,selenium-chromedriver,Selenium,Selenium Chromedriver,在使用Java的Selenium中,使用Chromedriver,我试图获取一个特定HTTPS请求的响应体。我使用的是日志条目,但我从日志中获取所有信息,除了响应主体。 有没有办法得到回应体 System.setProperty("webdriver.chrome.driver", "src\\test\\resources\\webdrivers\\chromedriver.exe"); ChromeOptions options = new ChromeOpt

在使用Java的Selenium中,使用Chromedriver,我试图获取一个特定HTTPS请求的响应体。我使用的是日志条目,但我从日志中获取所有信息,除了响应主体。 有没有办法得到回应体

        System.setProperty("webdriver.chrome.driver", "src\\test\\resources\\webdrivers\\chromedriver.exe");
        ChromeOptions options = new ChromeOptions();
        DesiredCapabilities cap = DesiredCapabilities.chrome();
        cap.setCapability(ChromeOptions.CAPABILITY, options);

        LoggingPreferences logPrefs = new LoggingPreferences();
        logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
        options.setCapability("goog:loggingPrefs", logPrefs);
        ChromeDriver driver = new ChromeDriver(options);
        System.out.println("Navigate to " + url);
        driver.navigate().to(url);

        LogEntries logs = driver.manage().logs().get("performance");

        for (Iterator<LogEntry> it = logs.iterator(); it.hasNext();) {
            LogEntry entry = it.next();
            try {
                JSONObject json = new JSONObject(entry.getMessage());
                JSONObject message = json.getJSONObject("message");
                String method = message.getString("method");
                if (method != null && "Network.responseReceived".equals(method)) {
                    method = message.getString("method");
                    JSONObject params = message.getJSONObject("params");
                    JSONObject response = params.getJSONObject("response");
                    String messageUrl = response.getString("url");
                    if (messageUrl.equals("https://pay.sandbox.realexpayments.com/api/auth"))
                        System.out.println(json.toString());
                }
         }
我是否遗漏了什么,或者可能有其他方法来实现这一点? 提前谢谢

试试下面的方法 导入io.restassured.restassured

公共类HttpResponseCode{

public int httpResponseCodeViaGet(String url) {

        return RestAssured.get(url).statusCode();

}

public int httpResponseCodeViaPost(String url) {

    return RestAssured.post(url).statusCode();

}

public static void main(String args[]) {

    new HttpResponseCode().httpResponseCodeViaGet("http://www.google.com");

}

}

它是故意漏掉的,因此您将无法获取它


Ref:

实际上,我只想记录不是我打的电话,而是应用程序本身的电话。有了重启,如果我打那个电话,我就能够得到回复,但不幸的是,这不是我的情况。
public int httpResponseCodeViaGet(String url) {

        return RestAssured.get(url).statusCode();

}

public int httpResponseCodeViaPost(String url) {

    return RestAssured.post(url).statusCode();

}

public static void main(String args[]) {

    new HttpResponseCode().httpResponseCodeViaGet("http://www.google.com");

}