startail Posted November 24, 2007 Share Posted November 24, 2007 Hi, I've been trying to use PHP with Curl to post a form with data to it and then get the returned result back to me for handling the data with the script. My problem is that I can't seem to make the ASP.NET server to return any results to me. This is my class for running curl to witch I send the data about the page it should load, like URI and Domain. Also if it should GET or POST to the page and to that the data it should send to the post. All this works very well. class getPage { var $ch = NULL; function __construct() { $this->ch = curl_init(); } function curlPage($page, $type="GET", $data=NULL) { $agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)\r\n"; $url = "{$page['domain']}/{$page['uri']}"; echo $url."\n\r"; if(is_array($values)) { foreach($values AS $key => $val){ $postValues .= urlencode($key) . "=" . urlencode($val) . "&"; } } else { $postValues = NULL; } $postValues = substr( $postValues, 0, -1 ); // Set cURL Specs curl_setopt($this->ch, CURLOPT_URL, $url); // HTTP URI curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); // Skriv inte ut data på skärmen #curl_setopt($this->ch, CURLOPT_USERAGENT, $agent); // Skicka Useragent curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 0); // Följ HTTP Header Location curl_setopt($this->ch, CURLOPT_COOKIEJAR, "cookie"); // Skriv Cookie Fil curl_setopt($this->ch, CURLOPT_COOKIEFILE, "cookie"); // Läs Cookie Fil curl_setopt($this->ch, CURLOPT_VERBOSE, 1); if($type == "POST") { curl_setopt($this->ch, CURLOPT_POST, 1); // Gör en standard POST (application/x-www-form-urlencoded) curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data); // Data att skicka till POST formet } $temp = curl_exec($this->ch); // Utför POST/GET return $temp; } } With using Curl I no longer have to worry about the cookies as It stores and sends them as it needs them, aside from what I tried before with fsockopen. What I do is this: 1. Call Curl to get a page to get the session cookie, the ASP.NET __VIEWSTATE and __EVENTVALIDATOR fields. 2. Call Curl to post a page with the __VIEWSTATE, __EVENTVALIDATOR and the form fields. The form fields that I post are ctl04$ucSimpleSearch$cmb_MarketPlace="0" ctl04$ucSimpleSearch$cmb_SubGroup="0" ctl04$ucSimpleSearch$cmb_RentLimit="0" ctl04$ucSimpleSearch$cmb_SeekArea="0" As it is now I expect this to work, but it doesn't seem to do just that. When I brows the page in my browser the first page I go to is "s2.aspx?page=pgStart". Here I submit the form. Then I get the results from this at the page called "s2.aspx?page=pgSearchResult". I now try to post my results to both these sites, but no results are returned. I think there are one or more steps to this procedure that I am missing to get it to work. Quote Link to comment https://forums.phpfreaks.com/topic/78689-post-aspnet-form-and-get-the-returned-result-with-php-and-curl/ Share on other sites More sharing options...
startail Posted November 28, 2007 Author Share Posted November 28, 2007 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/78689-post-aspnet-form-and-get-the-returned-result-with-php-and-curl/#findComment-401015 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.