http.basicAuth() function

The http.basicAuth() function returns a Base64-encoded basic authentication header using a specified username and password combination.

*Function type: Miscellaneous*

  1. import "http"
  2. http.basicAuth(
  3. u: "username",
  4. p: "passw0rd"
  5. )
  6. // Returns "Basic dXNlcm5hbWU6cGFzc3cwcmQ="

Parameters

u

The username to use in the basic authentication header.

*Data type: String*

p

The password to use in the basic authentication header.

*Data type: String*

Examples

Set a basic authentication header in an HTTP POST request
  1. import "monitor"
  2. import "http"
  3. username = "myawesomeuser"
  4. password = "mySupErSecRetPasSW0rD"
  5. http.post(
  6. url: "http://myawesomesite.com/api/",
  7. headers: {Authorization: http.basicAuth(u:username, p:password)},
  8. data: bytes(v: "something I want to send.")
  9. )