Last active
February 20, 2025 11:52
-
-
Save samuelstein/b110bc55a098d5a43d1086958ace8bd9 to your computer and use it in GitHub Desktop.
HTTP Requests with Selenium and Spring
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