karthikeyan_coder Posted January 28, 2007 Share Posted January 28, 2007 Hello, I need to fill a post method form,Submit and get result via CURL. i can get the remote form and i can fill it. After submitting the form url truns in to actual remote url.for example..<form ... action="https://somedomain.com/onsubmit.php"><input .. ></form>let us say above code is available in https://somedomain.com/form.phpmy code is...[code]<?phpfunction open_https_url($url,$refer = "",$usecookie = false) { if ($usecookie) { if (file_exists($usecookie)) { if (!is_writable($usecookie)) { return "Can't write to $usecookie cookie file, change file permission to 777 or remove read only for windows."; } } else { $usecookie = "cookie.txt"; if (!is_writable($usecookie)) { return "Can't write to $usecookie cookie file, change file permission to 777 or remove read only for windows."; } } } $post_data = array(); $post_data['name'] = "karthi"; $post_data['login'] = "keyan"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8118'); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); if ($usecookie) { curl_setopt($ch, CURLOPT_COOKIEJAR, $usecookie); curl_setopt($ch, CURLOPT_COOKIEFILE, $usecookie); } if ($refer != "") { curl_setopt($ch, CURLOPT_REFERER, $refer ); } curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $result =curl_exec ($ch); curl_close ($ch); return $result;}echo open_https_url("https://somedomain.com/form.php","",true);?>[/code]by this code i am getting a form. full form submission should be done behind a proxy. Any ideas? Link to comment https://forums.phpfreaks.com/topic/36095-curl-post-method-technique/ Share on other sites More sharing options...
Orio Posted January 28, 2007 Share Posted January 28, 2007 That's not the way you use cURL's post.Try this:[code]<?phpfunction open_https_url($url,$refer = "",$usecookie = false) { if ($usecookie) { if (file_exists($usecookie)) { if (!is_writable($usecookie)) { return "Can't write to $usecookie cookie file, change file permission to 777 or remove read only for windows."; } } else { $usecookie = "cookie.txt"; if (!is_writable($usecookie)) { return "Can't write to $usecookie cookie file, change file permission to 777 or remove read only for windows."; } } } $post_data = "name=karthi&login=keyan"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8118'); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); if ($usecookie) { curl_setopt($ch, CURLOPT_COOKIEJAR, $usecookie); curl_setopt($ch, CURLOPT_COOKIEFILE, $usecookie); } if ($refer != "") { curl_setopt($ch, CURLOPT_REFERER, $refer ); } curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $result =curl_exec ($ch); curl_close ($ch); return $result;}echo open_https_url("https://somedomain.com/form.php","",true);?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/36095-curl-post-method-technique/#findComment-171326 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.