如果有基本授权,如何在Node.js中使用http.client
根据标题,我该怎么做? 这是我的代码: var http = require('http'); // to access this url I need to put basic auth. var client = http.createClient(80, 'www.example.com'); var request = client.request('GET', '/', { 'host': 'www.example.com' }); request.end(); request.on('response', function (response) { console.log('STATUS: ' + response.statusCode); console.log('HEADERS: ' + JSON.stringify(response.headers)); response.setEncoding('utf8'); response.on('data', function (chunk) { console.log('BODY: …