Re: Submitting form with strange __multiselect parameters
Scott Battersby <[email protected]> Thu, 8 Aug 2013 12:18:24 +0930
| Newsgroups | gmane.comp.web.curl.php |
|---|---|
| Message-ID | <CACv0zNpPrr=EO8CjnGakR4v8WQjWT8mOJ=Sd2r9TuQhK=AT4aw@mail.gmail.com> |
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 <[email protected]> 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 <[email protected]> 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: [email protected] >> MSN: [email protected] >> 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