Node.js cannot decode string.. Characters garbled (question marks) -
i expected work but...
i getting base64 string in header... want encode utf8.
strinit = req.headers['authorization'] buf = new buffer(strinit.length) = 0 while < strinit.length buf[i] = strinit.charcodeat(i) i++ str = buf.tostring() str2 = new buffer(str, 'base64').tostring() console.log("auth request :",strinit, buf, str, str2) auth request : basic dxnlckbnbwfpbc5jb206cxdlcnr5 <buffer 42 61 73 69 63 20 64 58 4e 6c 63 6b 42 6e 62 57 46 70 62 43 35 6a 62 32 30 36 63 58 64 6c 63 6e 52 35> basic dxnlckbnbwfpbc5jb206cxdlcnr5 �"q�͕������������ݕ��
i tried decoding online , shows expected (user@gmail.com:qwerty)
for example here works fine: http://www.base64decode.org
what missing??
solved: ok, found ... had remove "basic" string decoder not confused..
so solution just:
new buffer(req.headers['authorization'].replace("basic ",""),"base64").tostring()
this way works.
Comments
Post a Comment