How to pass parameter in request body of restassured api in JAVA?

In below example, if i run this it is taking z as string, not as parameter, 

String z=   "1234";
        System.out.println("converted"+z);
        try {
            RestAssured.baseURI = "http://192.189.11.51:05/oceans/fssdata/";
            String requestBody ="{"CompanyID":z"
                    + ""
                    + ""
                    + "}";`

How to pass parameter Z in company ID, right now it is taking company id as z, i want it should take value of z.

Answer

You need to be careful with escaping the quotation marks when using strings directly. You can try using the code below.

String z = ""1234"";

String requestBody: "{"name":"+z+"}";

Leave a Reply

Your email address will not be published. Required fields are marked *