cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: Submitting form with strange __multiselect parameters

From: Oscar Vidal <oscarblo_at_gmail.com>
Date: Thu, 8 Aug 2013 23:23:16 +0800

Hi!

Thanks to Scott, Waruna and Thomas for the answers.

I tried each one of the suggestion but still getting same result.

*@Scott*

Your suggestion makes totally sense and I changed line to

curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode($str_postdata));

but still same result than before, see below the header returned

POST /realEstateIIWeb/resiRental/submitSearch.action HTTP/1.1
Host: www.ura.gov.sg
Accept: */*
Accept-Encoding: gzip
Content-Type: application/x-www-form-urlencoded
Content-Length: 380

*@Waruna*

I changed the String

$str_postdata="submissionType=pd&from_Date_Prj=JUN-2013&to_Date_Prj=JUN-2013&__multiselect_projectNameList=&__multiselect_selectedProjects=&propertyType=ac&from_Date=MAY-2013&to_Date=JUN-2013&__multiselect_postalDistrictList=&selectedPostalDistricts=01&selectedPostalDistricts=02&selectedPostalDistricts=03&__multiselect_selectedPostalDistricts=";

to a Array

$arr_postdata = array (
    'submissionType' => 'pd',
    'from_Date_Prj' => 'JUN-2013',
    'to_Date_Prj' => 'JUN-2013',
    '__multiselect_projectNameList' => null,
    '__multiselect_selectedProjects' => null,
    'propertyType' => 'lp',
    'from_Date' => 'MAR-2013',
    'to_Date' => 'JUN-2013',
    '__multiselect_postalDistrictList' => null,
    'selectedPostalDistricts' => 01,
    '__multiselect_selectedPostalDistricts' => null

    );

Note that in the array I cant add more than one "selectedPostalDistricts", so
I’m just using one district in the example.
I removed the header 'Content-Type: application/x-www-form-urlencoded'.
Cookies seems to be created and used by cURL.

POST /realEstateIIWeb/resiRental/submitSearch.action HTTP/1.1
Host: www.ura.gov.sg
Accept: */*
Accept-Encoding: gzip
Content-Length: 1280
Expect: 100-continue
Content-Type: multipart/form-data;
boundary=----------------------------ac09b91542ec

*@Rob

*
Also I followed your advice* *and I submitted the form to my local
computer, so I can see all the POST variables. But It seems like the java
script is not changing the form or at least the POST variables. I used the
a print_r($_POST) and this is what I can see:

Array ( [submissionType] => pd [from_Date_Prj] => JUN-2013 [to_Date_Prj] =>
JUN-2013 [projectNameList] => [__multiselect_projectNameList] =>
[__multiselect_selectedProjects] => [propertyType] => lp [from_Date] =>
MAR-2013 [to_Date] => JUN-2013 [__multiselect_postalDistrictList] =>
[selectedPostalDistricts] => 03 [__multiselect_selectedPostalDistricts] =>
)

----
I’m not sure what I can try more. Currently I’m thinking that it can be
related with the cookies that google analytics is creating in the website,
can it make sense?
Thanks!
Oscar
*
*
On 8 August 2013 10:48, Scott Battersby <scott_at_stopthatsnoring.com.au>wrote:
> you have to urlencode POST dataif you use the option "'Content-Type:
> application/x-www-form-urlencoded"
>
> the "-urlencoded" there is a big clue :)
>
> so change > curl_setopt($ch, CURLOPT_POSTFIELDS, $str_postdata);
>
> to
>
> > curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode($str_postdata));
>
> Cheers
>
> Scott
>
>
> On 7 August 2013 20:06, Oscar Vidal <oscarblo_at_gmail.com> wrote:
> > Hi Waruna!
> >
> > thanks for you answer.
> >
> > Here is the code that I'm using currently:
> >
> > --------------------------------------------------
> > $cookieFile="/tmp/cookie";
> >
> > $ch = curl_init();
> > curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
> > curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
> > curl_setopt($ch, CURLOPT_ENCODING, "gzip");
> > curl_setopt($ch, CURLOPT_URL, "http://www.some.url/submitSearch.action
> ");
> > curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:
> > application/x-www-form-urlencoded'));
> >
> > // The string is exactly the same that the one generated by the browser
> >
> $str_postdata="submissionType=pd&from_Date_Prj=JUN-2013&to_Date_Prj=JUN-2013&__multiselect_projectNameList=&__multiselect_selectedProjects=&propertyType=ac&from_Date=MAY-2013&to_Date=JUN-2013&__multiselect_postalDistrictList=&selectedPostalDistricts=01&selectedPostalDistricts=02&selectedPostalDistricts=03&__multiselect_selectedPostalDistricts=";
> >
> > curl_setopt($ch, CURLOPT_POST, 1);
> > curl_setopt($ch, CURLOPT_POSTFIELDS, $str_postdata);
> > curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
> > curl_setopt($ch, CURLOPT_VERBOSE, 1);
> >
> > curl_exec($ch);
> >
> > $info = curl_getinfo($ch, CURLINFO_HEADER_OUT);
> >
> > echo $info;
> >
> > curl_close($ch);
> > --------------------------------------------------
> >
> > The content of $info is
> >
> >
> > POST /submitSearch.action HTTP/1.1
> > Host: www.ura.gov.sg
> > Accept: */*
> > Accept-Encoding: gzip
> > Cookie: BIGipServerpl-prod_iplanet_http_v4=214476992.20480.0000;
> >
> JSESSIONID=vjyWSCpX2G9V1tKpTTHxcZh0t9nTyyqtjC291JrtXJC1vk70m0xm!-1705297486
> > Content-Type: application/x-www-form-urlencoded
> > Content-Length: 330
> >
> >
> > Hopefully it can give some clue about why the post to the form is not
> > working.
> > If I can add some other valuable info, please just ask me :)
> >
> > Thanks in advance!!
> > Oscar
> >
> >
> >
> > On 7 August 2013 17:44, Waruna Geekiyanage <waruna.ns_at_gmail.com> wrote:
> >>
> >> submit your PHP/cURL code, so that we can give a clear answer.
> >>
> >> Use following settings to submit POST data
> >>             curl_setopt ($ch, CURLOPT_POST, 1);
> >>             curl_setopt ($ch, CURLOPT_POSTFIELDS, $arr_postdata);
> >>
> >> $arr_postdata - field name as key and field data as value
> >>
> >> use following setting for debugging
> >>
> >> curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
> >> $info = curl_getinfo($ch, CURLINFO_HEADER_OUT);
> >>
> >> $info will give the request headers.
> >>
> >> Thank You,
> >> Waruna Geekiyanage
> >>
> >> M: +94 71 4168164
> >> E: waruna.ns_at_gmail.com
> >> MSN: warunans_at_hotmail.com
> >> GTalk: waruna.ns
> >> ICQ: 225184383
> >> Yahoo: warunans
> >> Skype: warunans
> >>
> >> On 8/7/2013 2:32 PM, Oscar Vidal wrote:
> >>
> >> Hi!
> >>
> >> I'm trying to submit a (java servlet) form using CURL in PHP, but it
> seems
> >> like there is a problem with the parameters. I cant really understand
> why
> >> its happening since I'm testing the CURL with a identical string
> parameters
> >> that is being used by the browser.
> >>
> >> After some research in diverse forums I wasn't able to find a solution
> to
> >> my particular problem.
> >>
> >> this is the POSTFIELDS string generated by the browser (and working):
> >>
> >>
> >>
> submissionType=pd&__multiselect_PostCodeList=&selectedPostCode=01&selectedPostCode=02&selectedPostCode=03&__multiselect_selectedPostCodes=
> >>
> >> and I'm using and identical (for testing) string in the PHP script but
> it
> >> im getting a HTML file as a answers telling "Missing parameters in
> search
> >> query".
> >>
> >> I believe that the form
> >>
> >> __multiselect_PostCodeList=
> >> &selectedPostCode=01
> >> &selectedPostCode=02
> >> &selectedPostCode=03
> >> &__multiselect_selectedPostCodes=
> >>
> >> is quite wired (never see before this) and I'm wondering that it can be
> >> the reason of why the post is not working from CURL.
> >>
> >> The form seems to be successfully submitted since I'm getting this
> header
> >>
> >> HTTP/1.1 200 OK
> >> Date: Wed, 07 Aug 2013 08:02:56 GMT
> >> Content-length: 1791
> >> Content-type: text/html;charset=UTF-8
> >> X-Powered-By: Servlet/2.4 JSP/2.0
> >> Vary: Accept-Encoding
> >> Content-Encoding: gzip
> >> Connection: Keep-Alive
> >>
> >> Note: I tried submitting the same form from Lynx and I'm also getting
> the
> >> same result ("Missing parameters in search query"). So it seems like its
> >> only working with browsers like Mozilla or Chrome.
> >>
> >> Please some help will be really appreciated, I don't have any more ideas
> >> at this point.
> >>
> >> Thanks! Oscar
> >>
> >>
> >>
> >> _______________________________________________
> >> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
> >>
> >>
> >
> >
> > _______________________________________________
> > http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
> >
>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
>

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2013-08-08