0 votes
1 view
in Salesforce by (11.9k points)

I'm trying to set POST content using Apex. The example below sets the variables using GET.

 PageReference newPage = Page.SOMEPAGE;

  SOMEPAGE.getParameters().put('id', someID);

  SOMEPAGE.getParameters().put('text', content);

Is there any way for me to set the HTTP type as POST?

1 Answer

0 votes
by (31.6k points)

You need to use HttpRequest class to set the HTTP type as POST.

String endpoint = 'http://www.example.com/service';

String body = 'fname=firstname&lname=lastname&age=34';

HttpRequest req = new HttpRequest();

req.setEndpoint(endpoint);

req.setMethod('POST');

req.setbody(body);

Http http = new Http();

HTTPResponse response = http.send(req);

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...