Page 1 of 1

cURL remote form with several pages+javascript problem

Posted: Tue Nov 11, 2008 5:45 am
by lipong
Hi

I`m trying to create a simple script that posts information into a remote form in a website and collects the output page. I decided to use cURL for this, the problems are the following:
-the form has more than one page
-it uses session id cookies.
-it uses JavaScript to validate and transform the data before posting it

I have managed to get the cookies working the problem is that whatever I try to post I always get a return of the form page and not the second form page as one gets if using a browser.
This is my code:

<?php
# Include http library
include("/home/luis/Desktop/personal+portugal/website/php_libs/LIB_http.php");


# Initiate addresses

#$ses=";jsessionid=CRFR5EWNT2OJXQFIAMFSFFGAVABQWIY4";
$action="https://www.millenniumbcp.pt/secure/33/3310_1.jhtml";
#$page2 = $action.$ses;
var_dump($page2);
$ref = "" ;
# Set submission method
$method="POST";
# Set form data and values
$data_array['/bcp/cidadebcp/33/SCHBean_diaNascimento']="1";
$data_array['_D:/bcp/cidadebcp/33/SCHBean_diaNascimento']=" ";
$data_array['/bcp/cidadebcp/33/SCHBean_mesNascimento']="1";
$data_array['_D:/bcp/cidadebcp/33/SCHBean_mesNascimento']="1";
$data_array['/bcp/cidadebcp/33/SCHBean_anoNascimento']="1990";
$data_array['_D:/bcp/cidadebcp/33/SCHBean_anoNascimento']="1990";
$data_array['eCivil']="0";
$data_array['_D:eCivil']="0";
$data_array['diaConj']="1";
$data_array['_D:diaConj']="1";
$data_array['mesConj']="1";
$data_array['_D:mesConj']="1";
$data_array['anoConj']="1990";
$data_array['_D:anoConj']=" 1990";
$data_array['/bcp/cidadebcp/33/SCHBean_agregadoFamiliar']="0";
$data_array['_D:/bcp/cidadebcp/33/SCHBean_agregadoFamiliar']="0";
$data_array['rendimentoBruto']="10000";
$data_array['_D:rendimentoBruto']="10000";
$data_array['/bcp/cidadebcp/33/SCHBean_anoFiscal']="0";
$data_array['_D:/bcp/cidadebcp/33/SCHBean_anoFiscal']="0";
$data_array['contaPoupHab']="false";
$data_array['_D:contaPoupHab']="false";
$data_array['Finalidade']="1";
$data_array['_D:Finalidade']="1";
$data_array['Propriedade']="0";
$data_array['_D:Propriedade']="0";
$data_array['Utilizacao']="0";
$data_array['_D:Utilizacao']="0";
$data_array['przEmp']="300";
$data_array['_D:przEmp']="300";
$data_array['_D:radioIMT']="false";
$data_array['radioIMT']="false";
$data_array['vFinan']="100000";
$data_array['_D:vFinan']="100000";
$data_array['vEscr']="120000";
$data_array['_D:vEscr']="120000";
$data_array['_D:vPatrim']=" ";
$data_array['/bcp/cidadebcp/33/SCHBean_diaEscritura']="0";
$data_array['_D:/bcp/cidadebcp/33/SCHBean_diaEscritura']="0";
$data_array['/bcp/cidadebcp/33/SCHBean_mesEscritura']="0";
$data_array['_D:/bcp/cidadebcp/33/SCHBean_mesEscritura']="0";
$data_array['/bcp/cidadebcp/33/SCHBean_anoEscritura']="0";
$data_array['_D:/bcp/cidadebcp/33/SCHBean_anoEscritura']="0";
$data_array['przCont']="";
$data_array['_D:przCont']=" ";
$data_array['Localizacao']="C";
$data_array['_D:Localizacao']="C";
$data_array['vAval']="126582,28";
$data_array['_D:vAval']="126582,28";
$data_array['radioSeguro']="";
$data_array['_D:radioSeguro']=" ";
$data_array['/bcp/cidadebcp/33/SCHBean_perSeguro']="0";
$data_array['_D:/bcp/cidadebcp/33/SCHBean_perSeguro']="0";
$data_array['_D:radioSegMH']=" ";
$data_array['_D:/bcp/cidadebcp/33/SCHBean_submit1']="1";
$data_array['_D:/bcp/cidadebcp/33/SCHBean_newSimul']=" ";
$data_array['_D:/bcp/cidadebcp/33/SCHBean_goToSectionHomePage']=" ";
$data_array['/bcp/cidadebcp/33/SCHBean_submit1_x']="58";
$data_array['/bcp/cidadebcp/33/SCHBean_submit1_y']="12";
$data_array['/bcp/cidadebcp/33/SCHBean_submit1']="1";


#var_dump($data_array);

$response = http_post_withheader($action, $ref, $data_array, INCL_HEAD);
#$response = http($target=$action, $ref, $method, $data_array, INCL_HEAD);
var_dump($response['FILE']);
var_dump($response['ERROR']);

?>

and the page I trying to post is the following: https://www.millenniumbcp.pt/secure/33/3310_1.jhtml

Any help would be much appreciated, I have exausted my options and nothing seems to work.

Thanks in advance.

Re: cURL remote form with several pages+javascript problem

Posted: Tue Nov 11, 2008 1:17 pm
by josh
I would debug something like this, by lets say enabling hte live http headers extension for firefox, and comparing the headers sent and received with the browser to the headers sent and received by Curl.

Re: cURL remote form with several pages+javascript problem

Posted: Wed Nov 12, 2008 7:59 am
by lipong
Hi

Thanks for the reply, I check both with cURL and in the browser and the problem is that php is not sending the fields for which I have set a empty value such as:

$data_array['_D:/bcp/cidadebcp/33/SCHBean_diaNascimento']=" ";

When I use the command line version of cURL then everything works fine and empty fields are sent.
Any ideas why this might be happening.

Thanks.

Re: cURL remote form with several pages+javascript problem

Posted: Wed Nov 12, 2008 11:03 am
by josh
empty as in null or one character of whitespace?

on your receiving end why dont you just check for non presence of a request variable and initialize the variable to be empty

how did you check in the browser and with curl ( what specific debugging steps did you go through in terms that I can understand )