I found this question and followed it downloading a file that comes as an attachment in a POST request response in PhantomJs. But the file it saves is an html file and says 404 - File or directory not found.
Is there something else I am missing to download this csv file?
Here are the response headers
Cache-Control:private
Content-Disposition:attachment;filename=LenderCompetitionReport.csv
Content-Length:249487
Content-Type:application/csv
Date:Tue, 08 Dec 2015 14:32:47 GMT
Pragma:
Server:Microsoft-IIS/7.0
Set-Cookie:NSC_JOy4ob05etjhas0d2kv5wzcdlqr2zbu=ffffffff09149e4f45525d5f4f58455e445a4a423660;expires=Tue, 08-Dec-2015 14:34:47 GMT;path=/;secure;httponly
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
And here is my code
casper.waitForSelector(x("//*[@id='ContentBody_ContentBody_btnExport']"),function() {
casper.then(function() {
var res = this.page.evaluate(function() {
var res={};
f=document.forms["frmBase"];
f.onsubmit= function() {
//iterate the form fields
var post={};
for(i=0; i<f.elements.length; i++) {
post[f.elements[i].name]=f.elements[i].value;
}
res.action = f.action;
res.post = post;
return false; //Stop form submission
}
//Trigger the click on the link.
var l = $("#ContentBody_BodyLevelElment_lbtnCsv");
l.click();
return res; //Return the form data to casper
});
//Start the download
casper.download(res.action, "LenderCompetitionReport.csv", "POST", res.post);
});
});