1
var zapClient = require('zaproxy');

const zapOptions = {
  key : 'abcdefghijklmn',
  proxy : 'http://localhost:8090/'
};

const zaproxy = new zapClient(zapOptions);

zaproxy.spider.scan("https://www.google.co.in");

i am trying to run above code i am getting : (node:8380) UnhandledPromiseRejectionWarning: RequestError: Error: socket hang up error.

i have tried socket hang up error with nodejs and "Request error: Socket hang up" with nodeJS on Amazon EC2 didn't help.

Lord Elrond
  • 13,430
  • 7
  • 40
  • 80
jai Balaji
  • 83
  • 1
  • 4
  • What happens if you delete the last line of your code, then run it? Do you still get the error? – Lord Elrond Mar 09 '19 at 18:27
  • if i remove last line it works fine – jai Balaji Mar 09 '19 at 18:34
  • Can you post a link to the source where you got `zaproxy.spider.scan` ? After quickly glancing at the [README](https://www.npmjs.com/package/zaproxy) for zaproxy, I didn't see that method used. the `.scan` part might be depreciated or meant to be used in a different way. – Lord Elrond Mar 09 '19 at 18:37
  • https://github.com/zaproxy/zaproxy/wiki/ApiGen_spider – jai Balaji Mar 09 '19 at 18:38

2 Answers2

0

I believe changing the last line of your code to this should fix the problem:

zaproxy.spider.scan("https://www.google.co.in", (err, res) => {
    if (err) throw err;

    //do something with res here
});

//can't do anything with res here
Lord Elrond
  • 13,430
  • 7
  • 40
  • 80
0

Also check the zap.log file - that might be logging errors which by default are not reported to the client (for security reasons - this can be disabled for testing)

Simon Bennetts
  • 5,479
  • 1
  • 14
  • 26