【问题标题】:'@' in URL, used in node.js http.requestURL中的'@',用于node.js http.request
【发布时间】:2012-07-24 09:57:09
【问题描述】:

我看到一个带有“@”符号的网址:

curl http://subdomain:token@localhost:9292/aaa/bbb

完美运行

但我无法让它与 node.js http.request 一起使用,可能是因为我不明白“@”在做什么(并且不知何故无法在谷歌上找到明确的答案)。

有人愿意解释一下吗?

这是我当前的 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

【问题讨论】:

  • 您正在尝试做的事情称为 http-auth。这是您正在寻找的答案的另一个问题:stackoverflow.com/questions/6918302/…
  • 所以 a:b@url 是基本 http-auth 的简写?
  • 差不多。我需要查看 RFC。

标签: http node.js url


【解决方案1】:

@ 将用户/密码部分与位置部分分开。

您编写的 curl 行随请求发送 HTTP Authenticate(BASIC 身份验证)。

curl http://subdomain:token@localhost:9292/aaa/bbb

表示:获取localhost:9292/aaa/bbb并以用户身份进行操作:subdomain密码token

我不知道如何在 node.js 中做到这一点,但你会弄明白的,现在你知道它做了什么。

【讨论】:

  • 太棒了,这让事情变得清晰;我会弄清楚节点部分
  • 只需将http_options 中的auth 设置为“subdomain:token”。
猜你喜欢
  • 1970-01-01
  • 2012-05-03
  • 1970-01-01
  • 2014-08-31
  • 2013-02-02
  • 2016-09-19
  • 2015-08-18
  • 2012-03-09
  • 1970-01-01
相关资源
最近更新 更多