HTTP Requests with Selenium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ResponseEntity<String> doJsonRequest(HttpMethod httpMethod, String path, Object body) throws URISyntaxException { | |
RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory()); | |
HttpHeaders headers = new HttpHeaders(); | |
headers.setContentType(MediaType.APPLICATION_JSON); | |
headers.add(COOKIE, getWebdriver().manage().getCookieNamed(YOUR_APP_COOKIE_NAME).toString()); | |
headers.setAccept(List.of(MediaType.APPLICATION_JSON, MediaType.TEXT_HTML)); | |
var request = new HttpEntity<>(body, headers); | |
return restTemplate.exchange(new URI("http", null, hostIpAddress, port, path, null, null), httpMethod, request, String.class); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment