username:password 作为base64编码的字符串 包含在Authorization标头 中 。
试试这个:
http.createServer(function(req,res){ var header=req.headers['authorization']||'', // get the header token=header.split(/s+/).pop()||'', // and the enpred auth token auth=new Buffer.from(token, 'base64').toString(), // convert from base64 parts=auth.split(/:/), // split on colon username=parts[0], password=parts[1]; res.writeHead(200,{'Content-Type':'text/plain'}); res.end('username is "'+username+'" and password is "'+password+'"');}).listen(1337,'127.0.0.1');有关http授权的详细信息,请参见http://www.ietf.org/rfc/rfc2617.txt



