大佬教程收集整理的这篇文章主要介绍了Node.JS中的基本HTTP身份验证?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
var http = require('http'); http.createServer(function (req,res) { res.writeHead(200,{'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337,"127.0.0.1");
,我不应该得到值的用户名:密码在req对象中的某处来自回调?
如何获得这些值,而不必使用Connect’s basic http auth?
尝试这个:
http.createServer(function(req,res){ var header=req.headers['authorization']||'',// get the header token=header.split(/\s+/).pop()||'',// and the encoded auth token auth=new Buffer(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
以上是大佬教程为你收集整理的Node.JS中的基本HTTP身份验证?全部内容,希望文章能够帮你解决Node.JS中的基本HTTP身份验证?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。