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



在Selenium中使用Java,使用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());
}
}

我得到这个 JSON 响应,它没有响应正文

{ 
"webview":"221612BC1DF99CA155A0301EEA4FBDAA",
"message":{ 
"method":"Network.responseReceived",
"params":{ 
"frameId":"221612BC1DF99CA155A0301EEA4FBDAA",
"requestId":"46320.53",
"response":{ 
"headers":{ 
"Keep-Alive":"timeout=20",
"Transfer-Encoding":"chunked",
"Server":"Apache Tomcat",
"Connection":"keep-alive",
"X-CONTENT-TYPE-OPTIONS":"nosniff",
"X-Application-Context":"HPPAzure:Azure:8080",
"Date":"Fri, 31 Jan 2020 12:27:30 GMT",
"Content-Type":"application/json;charset=UTF-8",
"Request-Context":"appId=cid-v1:d078d25d-db86-42cf-88e7-0d8f9ef12ee7"
},
"securityDetails":{ 
"cipher":"AES_256_GCM",
"signedCertificateTimestampList":[ 
{ 
"signatureData":"3044022056068FEDDA9F229659822AC94F5D35E8BEA1B99C1E4AA4681ED61604DF1AC033022064CFED8EA8FB473AEF690DF63F79FE693D4DF1ED612F09FA4C7A715A6952279E",
"logDescription":"Google 'Pilot' log",
"origin":"Embedded in certificate",
"logId":"A4B90990B418581487BB13A2CC67700A3C359804F91BDFB8E377CD0EC80DDC10",
"hashAlgorithm":"SHA-256",
"signatureAlgorithm":"ECDSA",
"status":"Verified",
"timestamp":1.537278661211E12
},
{ 
"signatureData":"3046022100A23157B9BF476E1602EA6654620173A78BC47F445E632FDEA433C6B8853D31E1022100F0FFD6115606BAE5FFF0EDDA34DC28BA392DCDC84AC5B1AF8B3D9620BE2850E5",
"logDescription":"DigiCert Log Server",
"origin":"Embedded in certificate",
"logId":"5614069A2FD7C2ECD3F5E1BD44B23EC74676B9BC99115CC0EF949855D689D0DD",
"hashAlgorithm":"SHA-256",
"signatureAlgorithm":"ECDSA",
"status":"Verified",
"timestamp":1.537278661319E12
},
{ 
"signatureData":"3044022060A1856FF22896D4388E3643132224C9371362F0E5CC0E92F9E9092ABFA8B61A02201433B88051A0E0B1D6814AA1D8CE5E1B45EDB404AE32546749C31947652AB686",
"logDescription":"Google 'Skydiver' log",
"origin":"Embedded in certificate",
"logId":"BBD9DFBC1F8A71B593942397AA927B473857950AAB52E81A909664368E1ED185",
"hashAlgorithm":"SHA-256",
"signatureAlgorithm":"ECDSA",
"status":"Verified",
"timestamp":1.53727866125E12
}
],
"protocol":"TLS 1.2",
"certificateId":0,
"certificateTransparencyCompliance":"compliant",
"sanList":[ 
"pay.sandbox.realexpayments.com"
],
"validFrom":1537228800,
"issuer":"Thawte EV RSA CA 2018",
"keyExchange":"ECDHE_RSA",
"keyExchangeGroup":"P-256",
"subjectName":"pay.sandbox.realexpayments.com",
"validTo":1606132800
},
"connectionReused":true,
"fromPrefetchCache":false,
"timing":{  },
"encodedDataLength":344,
"remotePort":443,
"mimeType":"application/json",
"securityState":"secure",
"url":"https://pay.sandbox.realexpayments.com/api/auth",
"protocol":"http/1.1",
"fromDiskCache":false,
"fromServiceWorker":false,
"remoteIPAddress":"52.155.173.65",
"statusText":"",
"connectionId":70,
"status":200
},
"loaderId":"0CB9CB8372A2D2D60E34F31ADDA813D5",
"type":"XHR",
"timestamp":3810237.716388
}
}
}

我是否错过了什么,或者也许还有其他方法可以实现这一点? 提前致谢

尝试如下操作 进口 io.放心.放心;

公共类 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");
}

}

它是故意省略的,所以你将无法得到它。

参考: https://bugs.chromium.org/p/chromedriver/issues/detail?id=2267&q=performance%20response%20body&can=1

相关内容

  • 没有找到相关文章

最新更新