Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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 (32.1k points)
edited by

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);

Want to become a salesforce Analyst, here's a Salesforce Course for you!

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
2 answers

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...