Jump to content

cURL help POSTing


raven74

Recommended Posts

I'm trying to submit a FORM using POST to a https site (only POST, GET is not allowed).

 

1. The site requires you to send required fields (theoretically using a FORM) to PAGE A. This POST creates a Java Servlet session id on PAGE A. No cookies are set on the browser that I know of.

 

2. Once part 1 is done, PAGE A has another FORM where you fill in more details and click on submit which submits the FORM to PAGE B. This submission finalizes the process.

 

I'm wondering if the whole process can be done with cURL. I tried sending parts 1 and 2 all at the same time with POST, but it doesn't work.

Can this be done ?

 

 

$ch = curl_init();    // initialize curl handle
curl_setopt($ch, CURLOPT_URL, "https://thesite.com/folder/PAGE A"); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // times out after 10s
curl_setopt($ch, CURLOPT_POST, true); // set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, "iputthepostfieldshere"); // add POST fields
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)");
$result = curl_exec($ch); // run the whole process
curl_close($ch);

Link to comment
https://forums.phpfreaks.com/topic/85672-curl-help-posting/
Share on other sites

You need to be absolutely sure there is not a cookie set. If you are using firefox and have 'web developer' tools installed you can see all the cookies set and their contents. IE you could set it to prompt you if a cookie is being set.

 

The values for post need to be run through the function urlencode(), not the entire post string or it will change the ampersands which you don't want changed.

Link to comment
https://forums.phpfreaks.com/topic/85672-curl-help-posting/#findComment-437262
Share on other sites

I double checked and no cookies are used anywhere in the https site. I also urlencode the values.

 

In my original code I only wrote the POST to PAGE A but how, if possible, can I write the code so I can also POST to PAGE B ? (The Java Servlet session id is appended to the FORM in PAGE A.) Is that session id relevant at all ?

Link to comment
https://forums.phpfreaks.com/topic/85672-curl-help-posting/#findComment-437272
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.