Receive {
"contentType": "text/plain",
"headers": [
{
"name": "Cache-Control",
"value": "private"
},
{
"name": "Content-Length",
"value": "256"
},
{
"name": "Content-Type",
"value": "text/plain"
},
{
"name": "Server",
"value": "Microsoft-IIS/7.0"
},
{
"name": "X-AspNet-Version",
"value": "4.0.30319"
},
{
"name": "Content-Disposition",
"value": "attachment; filename=\"ContactList_08-25-14.csv\""
},
{
"name": "X-Powered-By",
"value": "ASP.NET"
},
{
"name": "p3p",
"value": "policyref=\"/w3c/p3p.xml\", CP=\"COM CNT DEM FIN GOV INT NAV ONL PHY PRE PUR STA UNI IDC CAO OTI DSP COR CUR OUR IND\""
},
{
"name": "Date",
"value": "Mon, 25 Aug 2014 12:19:25 GMT"
}
],
"id": 104,
"redirectURL": null,
"stage": "end",
"status": 200,
"statusText": "OK",
"time": "2014-08-25T12:19:30.605Z",
"url": "http://xxxxxxxxxx.com/xxxxxxxx/ExportSubscribers.aspx"
}

- 28,279
- 5
- 35
- 57

- 1
- 2
-
Please describe what you want to do and what your specific problem is, **in the question body itself.** What does this question have to do with jQuery? Where does this Object come from (show the code that generated it). – Artjom B. Aug 25 '14 at 12:30
-
possible duplicate of [downloading a file that comes as an attachment in a POST request response in PhantomJs](http://stackoverflow.com/questions/16144252/downloading-a-file-that-comes-as-an-attachment-in-a-post-request-response-in-pha) – Artjom B. Jul 24 '15 at 15:42
3 Answers
No code in this answer, sorry.
But you don't need a headless browser, all you need is the raw response body. So just read Content-Length
(256) bytes of response body and put them somewhere. They should contain the actual file contents.
This approach should work for any content type, in your example it's text/plain
but sometimes it may be application/...
and then the response body will contain binary data.
As a side note, HTML pages are text/html
and they are not sent as attachments.
Also, since you already have those response headers converted to an array, you can retrieve the suggested filename from the server to save it locally.

- 10,565
- 6
- 50
- 72
I have suceeded. There is a beta version of phantomjs 2.0 that includes an event handler that solves this issue.
It is still a beta version, so there is no debugging.
So i have developed the clicks and the page treatments on the release version and then changed the phantom version to make download work.
casper.start('http://www.website.com.br/', function() {
this.page.onFileDownload = function(status){console.log('onFileDownload(' + status + ')');
//SYSTEM WILL DETECT THE DOWNLOAD, BUT YOU WILL HAVE TO NAME THE FILE BY YOURSLEF!!
return "ContactList_08-25-14.csv"; };
});
casper.then(function() {
//DO YOUR STUFF HERE TO CLICK ON THE DOWNLOAD LINK.
});
casper.run();
Download: Phantom 2.0 BETA
Download the exe, rename the release version of phantom.exe to phantom.bkp.exe and insert this 2.0 version on the place. Then, in casperjs you will need to add some lines at the beggining of casperjs/bin/bootstrap.js
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
var system = require('system');
var argsdeprecated = system.args;
argsdeprecated.shift();
phantom.args = argsdeprecated;
also comment the version check (same file):
(function(version) {
// required version check
/* if (version.major !== 1) {
return __die('CasperJS needs PhantomJS v1.x');
} if (version.minor < 8) {
return __die('CasperJS needs at least PhantomJS v1.8 or later.');
}
if (version.minor === 8 && version.patch < 1) {
return __die('CasperJS needs at least PhantomJS v1.8.1 or later.');
} */
})(phantom.version);
Remember, this is a tweak!!.
So this lines on bootstrap will cause problems if you want to run phantom release version or slimerjs.
So DEVELOP ON RELEASE VERSION, than tweak to this version to be able to download. If you need to debug, you will have to remove the lines of bootstrap.js

- 151
- 1
- 10
I am also trying based on this post: https://stackoverflow.com/a/23521991/3156756
I did not suceeded already because my form does not have an ID, just a name. But i am trying to be able to do this type of download too.

- 1
- 1

- 151
- 1
- 10