raven74 Posted January 12, 2008 Share Posted January 12, 2008 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); Quote Link to comment Share on other sites More sharing options...
Daukan Posted January 12, 2008 Share Posted January 12, 2008 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. Quote Link to comment Share on other sites More sharing options...
raven74 Posted January 12, 2008 Author Share Posted January 12, 2008 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 ? Quote Link to comment Share on other sites More sharing options...
Daukan Posted January 12, 2008 Share Posted January 12, 2008 I would say the session id is important. You have to send the second page. With the all the form fields populated most likely. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.