Jump to content

Post ASP.NET Form and get the returned result with PHP and Curl


Recommended Posts

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.