Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP 407 CasperJS through corporate proxy

I'm trying to use casperjs to access creditkarma.com (which isn't blocked by the firewall). But I keep getting a 407 error and a page that says I need to provide a username and password, no form just an error. I tried http://username:[email protected]. I also tried --proxy with --proxy-auth I also tried sending headers.

casper.options.pageSettings = {
    customHeaders:{
        'Authorization':'Basic '+btoa('myUserName:myPassword')
    }
}

The command is running through the windows command prompt so I also set HTTP_PROXY. I have spent a few hours on this and cannot seem to figure out why this won't work. Does anyone have other ideas I can try?

like image 882
Michael St Clair Avatar asked Jun 08 '26 10:06

Michael St Clair


1 Answers

Judging by 407 response you have to 1. Use proxy 2. Supply proxy auth requisites.

In CasperJS (and PhantomJS) you do:

casperjs --proxy=192.168.0.100:8080 --proxy-auth=user:pass ck.js

Also, seeing as the target site uses https protocol only, you would do well to include in the list of arguments instructions to prevent ssl errors.

casperjs --ignore-ssl-errors=yes --ssl-protocol=any --proxy=192.168.0.100:8080 --proxy-auth=user:pass ck.js

In case NTLM authorization required, it is present in PhantomJS from version 2.0.0, but CasperJS doesn't yet support that version. You could enable a local NTLM proxy to bypass that restriction and still use CasperJS as shown in this answer: cntlm proxy with phantomjs

like image 91
Vaviloff Avatar answered Jun 10 '26 19:06

Vaviloff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!