简体   繁体   中英

5-parameter AJAX request node.js

The XMLHttpRequest constructor has a five-argument version that takes a user name and password (I believe that jQuery's $.ajax uses it under the hood). I cannot for the life of me figure out from the Joyent docs, SO, logging every nook and cranny of the request object, and the Necronomicon how to access that username and password in Node's http module (or in any middleware layer over top of it).

Most Node authentication seems to be based around using the auth header or third-party plugins (eg google, facebook). Which is fine, but I'm still curious if the user name and password from the 5-parameter xhr request can be accessed in Node.

I don't think it's available. To test, I ran a minimal node.js server:

var http = require('http')
var server = http.createServer(function(req, res){
  console.dir(req, { depth:10 })
})
server.listen({port:5000})

Then made an XHR request like so:

var xhr = new XMLHttpRequest()
xhr.open('GET', 'http://localhost:5000', true, 'mike', 'pass')
xhr.send()

Which outputs a ton of info ( found here ), none of which contains mike or pass for username and password.

The same is true if I make the request using curl like so: curl mike:pass@localhost:5000

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM