resopollution
resopollution

Reputation: 20350

Node.js HTTPS request with username

I'm trying to query api.whatever.com, but I also want to pass a USERNAME, such as in curl it would look like this:

https://[email protected]/

How do I write the client request in such a way that USERNAME gets sent properly to the API server.

Upvotes: 0

Views: 406

Answers (2)

hsc
hsc

Reputation: 96

You need to base64 encode the username.

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

Upvotes: 1

thejh
thejh

Reputation: 45578

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

There's an explaination of the format you have to use as well as an example.

Upvotes: 1

Related Questions