2012-07-25 92 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

相關問題