带有用户名的Node.js HTTPS请求

时间:2011-08-19 07:54:56

标签: http node.js https request httpclient

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

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

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

2 个答案:

答案 0 :(得分:1)

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

对您必须使用的格式以及示例进行了解释。

答案 1 :(得分: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];
相关问题