function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Diwakar G 7Diwakar G 7 

Passing Json to call post method

Hi,
Please help me in creating body using Apex. I need to pass the body in post method.
[
    { "n": "MyApexClass", "r": false,  "t": "ApexClass" },
    { "n": "SysAdmin", "r": false, "t": "Profile" },
    { "n": "Account", "r": true, "t": "CustomObject" }
 ]

Thanks and Regards,
Diwakar G
Raj VakatiRaj Vakati
Refer this code
 
// Sening the http body with JSON 
String jsonData ='[{ "n": "MyApexClass", "r": false,  "t": "ApexClass" },{ "n": "SysAdmin", "r": false, "t": "Profile" },{ "n": "Account", "r": true, "t": "CustomObject" }]' ; 
String endpoint = 'http://www.example.com/service';
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setMethod('POST');
req.setbody(jsonData);
Http http = new Http();
HTTPResponse response = http.send(req);