【问题标题】:Node.js HTTPS request with username带有用户名的 Node.js HTTPS 请求
【发布时间】:2011-08-19 07:54:56
【问题描述】:

我正在尝试查询 api.whatever.com,但我也想传递一个 USERNAME,例如在 curl 中它看起来像这样:

https://USERNAME@api.whatever.com/

如何编写客户端请求以使 USERNAME 正确发送到 API 服务器。

【问题讨论】:

  • 使用 HTTP Header 进行身份验证

标签: http node.js https request httpclient


【解决方案1】:

您需要对用户名进行 base64 编码。

url = "https://USERNAME@api.whatever.com/".replace("https://","").split("@");
// Buffer is global, no need for require.
url64 = "https://" + (new Buffer(url[0]).toString('base64')) + url[1];

【讨论】:

    【解决方案2】:

    http://en.wikipedia.org/wiki/Basic_access_authentication

    您必须使用的格式说明以及示例。

    【讨论】:

      猜你喜欢
      • 2013-12-01
      • 1970-01-01
      • 2019-05-13
      • 1970-01-01
      • 2018-06-14
      • 2012-02-06
      • 1970-01-01
      • 1970-01-01
      • 2011-12-26
      相关资源
      最近更新 更多