2012-07-25 45 views
0

用我带有一个URL以 “@” 符号在里面:'@' 的URL,在node.js中http.request

curl http://subdomain:[email protected]:9292/aaa/bbb 

作品完美

但我可以”不要让它与node.js http.request一起工作,可能是因为我不明白“@”在做什么(并且无法在google上找到明确的答案)。

有人在乎解释吗?

这是我目前的Node.js代码

var http_options = { 
    method : "GET" 
, url : subdomain + ":" + token + "@" + Config.API.url 
, path : "/aaa/bbb" 
}; 

var req = http.request(http_options, function (response) { 
    // ... 
}); 

req.on('error', function (error) { 
    console.log('error: ' + error); 
}); 

主要生产:

error: ECONNREFUSED 
+0

你想要做的就是所谓的http-auth。这是你正在寻找的答案的另一个问题:http://stackoverflow.com/questions/6918302/http-client-based-on-nodejs-how-to-authenticate-a-request – 2012-07-25 21:16:56

+0

所以a:b @ url是基本http-auth的简写? – Max 2012-07-25 21:19:50

+0

非常。我需要看看RFC(s)。 – 2012-07-25 21:33:30

回答

2

的@是将用户名/密码部分从位置部分。

您写的卷曲线发送HTTP请求的Authenticate(BASIC认证)。

curl http://subdomain:[email protected]:9292/aaa/bbb 

是指:获得localhost:9292/aaa/bbb并做到这一点的用户:subdomain密码token

我不知道该怎么做,在node.js的,但你看着办吧,现在你知道什么它确实如此。

+0

真棒,这让事情变得清晰;我会找出节点部分 – Max 2012-07-25 21:20:45

+1

只需在'http_options'中将'auth'设置为“subdomain:token”即可。 – ebohlman 2012-07-26 00:31:11

相关问题