In Basic Authentication, a HTTP request contains a header
Authorization: Basic <credentials>, where credentials is the Base64 encoding of username and password joined by a single colon
Basic Auth is considered as not safe enough, but we still use it a lot for some less sensitive stuff because it is easy to set up.
You can use Basic Http Auth with curl in following two ways:
Passing Basic credentials to curl command is easy as this:
curl -u username:password https://example.com
If your username or password contains a special character, such as white-space, then you might want to surround credentials with single quotes:
curl -u 'username:password' https://example.com
If you want to have a full control over your HTTP request, you might want to Base64 encode your
username:password and place it into
Curl command should look like this:
curl -H 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=' https://example.com
: is not allowed to be used in an username according to Basic Auth specification. But in case you need to support it (ie your users are allowed to create such username) and you are in charge of client and server, you might want to URL encode the username and password on both sides.