You need to sign in to do that
Don't have an account?

How to pass parmas to external URL by POST rather than GET in controller?
Hi All,
What I need to implement:
A VF page includes a command button "Date Entry", once users click the button, a few pramas need to be past (use POST rather than GET) to external data entry website, the page also need to be redirected to external data entry website.
I googled many related solutions, they all use GET which is appended all parameters in URL, such as:
---------------------------------------------------------------------------------
public PageReference redirect2DataEntry(){
PageReference pageRef = new PageReference('https://www.dataentry.com/login');
pageRef.getParameters().put('username', 'abc');
pageRef.getParameters().put('passcode', 'xyz');
.... ....
return pageRef;
}
------------------------------------------------------------------------------
My question is, can we use POST (append params in HTTP header) to pass the parameters? Some one mentioned that HttpRequest class can be used to send POST request (see below), but the problem is how can I redirect to external web page at the same time by using HttpRequest class in the controller?
-----------------------------------
String endpoint = 'http://www.example.com/service';
String body = 'fname=firstname&lname=lastname&age=34';
HttpRequest req = new HttpRequest();
req.setEndpoint(enpoint);
req.setMethod('POST');
req.setbody(body);
Http http = new Http();
HTTPResponse response = http.send(req);
---------------------------------------------------------------------------------
Thanks in advance.
What I need to implement:
A VF page includes a command button "Date Entry", once users click the button, a few pramas need to be past (use POST rather than GET) to external data entry website, the page also need to be redirected to external data entry website.
I googled many related solutions, they all use GET which is appended all parameters in URL, such as:
---------------------------------------------------------------------------------
public PageReference redirect2DataEntry(){
PageReference pageRef = new PageReference('https://www.dataentry.com/login');
pageRef.getParameters().put('username', 'abc');
pageRef.getParameters().put('passcode', 'xyz');
.... ....
return pageRef;
}
------------------------------------------------------------------------------
My question is, can we use POST (append params in HTTP header) to pass the parameters? Some one mentioned that HttpRequest class can be used to send POST request (see below), but the problem is how can I redirect to external web page at the same time by using HttpRequest class in the controller?
-----------------------------------
String endpoint = 'http://www.example.com/service';
String body = 'fname=firstname&lname=lastname&age=34';
HttpRequest req = new HttpRequest();
req.setEndpoint(enpoint);
req.setMethod('POST');
req.setbody(body);
Http http = new Http();
HTTPResponse response = http.send(req);
---------------------------------------------------------------------------------
Thanks in advance.
Set them in your request body. Something like this ->