+ Start a Discussion
Apipoj PiasakApipoj Piasak 

Apex cURL callout to store login value to cookie.

Hello there,

I an trying to implement the API cURL callout to post the login form and would like to store the credential into cookie. Sample are the script.
login_form <- c()
login_form$email <- username
login_form$password <- password
curlHandler <- getCurlHandle(cookiefile = "cookies.jar", verbose = TRUE)
postForm("https://test.com/login",  .params = login_form,  curl = curlHandler)
I wonder of how to integrate this into Apex class / trigger ? Is there anyone having the experience on this?

Are you trying to make an apex callout and set a cookie value?  Or are you trying to store a cookie in Apex to use in a Visualforce page later?
Apipoj PiasakApipoj Piasak
Hi pcon,

We would like to store a cookie as a credential to use in another cURL post form. Would it be possible?
Can you please take a step back and explain exactly what you are trying to do and where you are trying to do it from.  You would not be doing anything with cURL inside of Salesforce.
Apipoj PiasakApipoj Piasak

We would like to use Apex class/trigger to submit a HTML form. But this form need to log in first and it allow only Cookie for authentication.

Here are the detail of the requirments.
1. Submit login form with cURL
2. Store login credential into Cookie
3. Submit the target form with cURL

Is that something that SF could do about this?

You'll do this with a standard apex callout [1] to your REST endpoint and get your data out of the response.  Then you'll set the Cookie via the header on the second callout [2].

[1] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts.htm
[2] http://stackoverflow.com/questions/11670593/setting-cookie-from-webservice-call-out-in-salesforce