diff --git a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/RestClient.java b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/RestClient.java index f50f4b6acc..43f706f58c 100644 --- a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/RestClient.java +++ b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/RestClient.java @@ -13,6 +13,7 @@ import io.mosip.testrig.apirig.testrunner.MosipTestRunner; import io.restassured.RestAssured; +import io.restassured.config.EncoderConfig; import io.restassured.config.HttpClientConfig; import io.restassured.config.RestAssuredConfig; import io.restassured.http.Cookie; @@ -1763,4 +1764,24 @@ public static Response postRequestWithQueryParamBodyAndCookie(String url, Object return postResponse; } -} + + public static byte[] postRequestWithFormDataBodyForPdf(String url, Map formData) { + byte[] pdf; + GlobalMethods.addToServerEndPointMap(url); + + EncoderConfig encoderConfig = new EncoderConfig().encodeContentTypeAs("application/x-www-form-urlencoded", + io.restassured.http.ContentType.URLENC); + RESTCLIENT_LOGGER.info("REST-ASSURED: Sending a POST request to " + url); + + if (ConfigManager.IsDebugEnabled()) { + pdf = given().config(config.encoderConfig(encoderConfig)).relaxedHTTPSValidation().formParams(formData) + .contentType("application/x-www-form-urlencoded").log().all().when().post(url).then().extract() + .asByteArray(); + } else { + pdf = given().config(config.encoderConfig(encoderConfig)).relaxedHTTPSValidation().formParams(formData) + .contentType("application/x-www-form-urlencoded").when().post(url).then().extract().asByteArray(); + } + + return pdf; + } +} \ No newline at end of file