Skip to content

Instantly share code, notes, and snippets.

@samuelstein
Created November 18, 2020 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelstein/b110bc55a098d5a43d1086958ace8bd9 to your computer and use it in GitHub Desktop.
Save samuelstein/b110bc55a098d5a43d1086958ace8bd9 to your computer and use it in GitHub Desktop.
HTTP Requests with Selenium
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