views:

118

answers:

1

Hello,

I can't find anything in the docs on exactly how to do this.

http://nodejs.org/api.html#request-method-149

I need to make a Node js POST with authorization something similar to this in ruby:

url = URI.parse('http://www.example.com/todo.cgi')
    req = Net::HTTP::Post.new(url.path)
    req.basic_auth 'jack', 'pass'

I am trying to essentially do this:

var client = http.createClient(80, 'http://api.foo.com');
  var rq = client.request('POST', '/path/', 
  {
    'authorization' : [account, password]
    'key': value,
    etc....
  }
+2  A: 

Just encode the string account:password in base64 using a Buffer and set it has header with the key Authorization, prefixed with the word Basic.

PartlyCloudy