Below is the best way to construct the request body, sample code for constructing request body and hit the service:

String requestbody="";
    requestbody="{"+
        ""args": {},"+
        ""headers": {"+
        ""Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","+
        ""Accept-Encoding": "gzip, deflate","+
        ""Accept-Language": "en-US,en;q=0.9","+
        ""Host": "yourapihere.com","+
        ""Upgrade-Insecure-Requests": "1","+
        ""User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36""+
        "},"+
        ""method": "GET","+
        ""origin": "103.43.112.97","+
        ""url": "http://yourapihere.com/""+
        "}";

HttpClient httpClient =new HttpClient();
PostMethod postMethod=new PostMethod(url);
postMethod.setRequestEntity(new StringRequestEntity(requestBody, null, "UTF-8"));
postMethod.setRequestHeader("Content-Type", "application/; charset=UTF-8");
        postMethod.setRequestHeader("Accept", "application/; charset=UTF-8");
int statuscode=httpClient.executeMethod(postMethod);
String responsebody2=postMethod.getResponseBodyAsString();
System.out.println(responsebody2);

for more details, check out this Video.



Source link https://sqa.stackexchange.com/questions/14652/-me-the-best-way-to-----with-json-using-

LEAVE A REPLY

Please enter your comment!
Please enter your name here