How do you pass headers in a POST request using RestAssured library in Java
Anonymous
public class ExampleTest { @Test public void testPostWithHeaders() { // Set up the RestAssured base URI and port RestAssured.baseURI = "https://example.com"; RestAssured.port = 80; // Set up the headers String header1 = "header1Value"; String header2 = "header2Value"; // Set up the request body String requestBody = "{\"key1\": \"value1\", \"key2\": \"value2\"}"; // Send the POST request with headers using RestAssured given() .header("Header1", header1) .header("Header2", header2) .contentType(ContentType.JSON) .body(requestBody) .when() .post("/api/endpoint") .then() .statusCode(200); // Use Selenium to navigate to a web page and perform some action WebDriver driver = new ChromeDriver(); driver.navigate().to("https://example.com"); driver.findElement(By.id("searchField")).sendKeys("RestAssured"); driver.findElement(By.id("searchButton")).click(); driver.quit(); } }
Check out your Company Bowl for anonymous work chats.