cURL / Mailing Lists / curl-users / Single Mail

curl-users

Confused about urlencoding POSTFIELDS. Am I doing it

From: nikhil jain <nik.jain_at_gmail.com>
Date: Thu, 07 Jul 2011 05:47:12 +0530

I am trying to post to a form on this page:
http://198.173.15.31/V2/COUNTY/Default.aspx (Search by name)

The raw POST DATA according to a firefox extension when posting to the
site is as follows:

ctl00$ScriptManager1=ctl00$ContentPlaceHolder1$CaseUpdatePanel|ctl00$ContentPlaceHolder1$SearchButton&__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE={SUPER
LONG STRING
SNIPPED}&__VIEWSTATEENCRYPTED=&quickjump=%23&ctl00$ContentPlaceHolder1$NameSearch1$CompanyNameTextBox1=nikhil&ctl00$ContentPlaceHolder1$SearchButton=Search%20Now

--------------
Relevant portion of my php script which attempts to POST to the form (The
script is unable to post properly to get the desired result);

  $postfields_array = array ( 'ctl00$ScriptManager1' =>
'ctl00$ContentPlaceHolder1$CaseUpdatePanel|ctl00$ContentPlaceHolder1$SearchButton'
, '__EVENTTARGET' => '' , '__EVENTARGUMENT' => '' , '__VIEWSTATE' =>
$viewStateValue , '__VIEWSTATEENCRYPTED' => '' , 'quickjump' => '#' ,
'ctl00$ContentPlaceHolder1$NameSearch1$CompanyNameTextBox1' => $name ,
'ctl00$ContentPlaceHolder1$SearchButton' => 'Search Now' ) ;
   $encoded = '';
  foreach($postfields_array as $name => $value)
  {
     $encoded .= urlencode($name).'='.urlencode($value).'&';
  }

$postfields = substr($encoded, 0, strlen($encoded)-1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postfields );

---------------

The raw POST DATA according to wireshark while POSTING from my script is
as follows:

ctl00%24ScriptManager1=ctl00%24ContentPlaceHolder1%24CaseUpdatePanel%7Cctl00%24ContentPlaceHolder1%24SearchButton&__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE={SUPER
LONG STRING
SNIPPED}&__VIEWSTATEENCRYPTED=&quickjump=%23&ctl00%24ContentPlaceHolder1%24NameSearch1%24CompanyNameTextBox1=jenna&ctl00%24ContentPlaceHolder1%24SearchButton=Search+Now

Question:
As the docs say I have urlencoded the postfields . But as can I see it the
POST DATA is clearly different when using the site normally , and when
trying to POST via php-curl. Why? does it matter? if so what is the
solution?

Thanks
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-07-07