I have a scenario : A user needs to fill a form and after submitting, it should send the data of the form using POST API to some URL -
the user will need to be redirected to this page after the params passed to this URL, to this site.
I've tried to use the HttpRequest class and pass the params inside the body - But I didn't find a way to make a follow redirection to the page.
Using PageReference - don't sure how to send it using post - If I don't get wrong here - it always sent as a GET method - or not? When I tried to send it using PageReference - it using GET method and send the params through URL - I need them to be hidden from there.
Someone can help me with this?
The first method I tried using PageRefence : PageReference :
public PageReference doSave() {
PageReference pageRef = new PageReference('https://www.someSite/payment/index.php/landing');
pageRef.getParameters().put('email','[email protected]');
pageRef.getParameters().put('name','testName');
pageRef.getParameters().put('token','343434');
pageRef.getParameters().put('Id','343434');
return pageRef;
}
The Second method I tried using HttpRequest (after making the Page Refernce in comment): HttpRequest:
public void sendData(){
System.debug('sendData!');
String endpoint = 'https://www.someSite/payment/index.php/landing';
String body = '[email protected]&name=salv&token=a108e884&Id=23456';
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setMethod('POST');
req.setbody(body);
Http http = new Http();
HTTPResponse response = http.send(req);
}
Many thanks!