I am unclear as to how form submission works (and getting a response). The web form is attached. Normally submitting the form through the browser results in an excel file being returned (a "save as" dialog box opens).
Here is the code I have tried using Prowser:
Tab tab = new Prowser().createTab();
try{
Request rq=new Request("http://user:pwd@webpage");
rq.setHttpMethod("POST");
rq.addParameter("start_month", "10");
rq.addParameter("start_date", "1");
rq.addParameter("start_year", "2010");
rq.addParameter("start_month", "10");
rq.addParameter("start_date", "31");
rq.addParameter("start_year", "2010");
Response response = tab.go(rq);
System.out.println(response.getPageSource());
This simply prints out the webpage. I can't figure out there the response object contains the excel file.
I also tried this (addition to the above code):
byte[] fileContents = tab.go(rq).getPageBytes();
try{
// Create file
FileWriter fstream = new FileWriter("out.txt");
BufferedWriter out = new BufferedWriter(fstream);
int size=fileContents.length;
for(int i=0;i<size;i++)out.write(fileContents[i]);
//Close the output stream
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
catch(Exception e){}
finally{}
This results again in the page source code being written to the output file.
I hope you can help. Thanks in advance.