Upload file to CasperJS domain

I cannot download a file stream from a web server using CasperJS:

  • the form is sent to the url
  • url returns file stream

So far, I have confirmed that the correct form values ​​are posted.

var casper = require('casper').create({ verbose: true, logLevel: 'debug', viewportSize: {width: 1440, height: 800}, pageSettings: { userName: '****', password: '****', webSecurityEnabled: false }, waitTimeout: 200000 }); casper.start("***"); casper.then(function() { var exportForm = this.evaluate(function() { return $("#export_pdf_form").serialize(); }); var exportAction = this.evaluate(function() { return $("#export_pdf_form").attr('action'); }); var url, file; url = '***' + exportAction; (eg. https://webserver/export) file = "export.pdf"; casper.page.settings.webSecurityEnabled = false; casper.download(url, fs.workingDirectory + '/' + file, "POST", exportForm); }); 

Casper error "Unfortunately, casperjs cannot execute ajax requests for cross domains", followed by "XMLHttpRequest 101 exception". After searching, it indicates that setting the Internet security variable to false should do the job ... but it doesn’t. What else should I learn?

casperjs - v1.1.1 phantomjs - v2.0.0

+5
source share
3 answers

It turns out that there is nothing wrong with my code, just updating PhantomJS from 2.0.0 to 2.1.1 solved the problem.

0
source

Alternative answer: you can implement a proxy server through the API through your site. Warning. It’s best to run only the resources that you control, as this requires your site to be responsible for the content, and may compromise your certificate if you allow malicious or untrusted content.

0
source

There is a lot of material for cross-domain AJAX protection policies of the same origin that are viewed there, look. As far as I know, there are only two alternatives to the one suggested by John (proxy setting on the server side):

1. Using the standard W3C CORS technique and HTTP headers.

https://en.wikipedia.org/wiki/Cross-origin_resource_sharing

2. The JSONP mechanism.

https://en.wikipedia.org/wiki/JSONP

I really don’t know if this is really the real problem you are experiencing, but I hope this helps you.

-1
source

Source: https://habr.com/ru/post/1236174/


All Articles