An example of making a POST request with Basic Authentication credentials using Curl. Basic Authentication credentials are passed to Curl with the --user "login: password" command-line option. The user's credentials are automatically converted by Curl to a Base64 encoded string and passed to the server with an Authorization: Basic [token] header. POST data is passed to Curl with the -d option. In this Curl POST with Basic Authentication header example, we sent a request to the ReqBin echo URL. Click Run to execute the Curl request online and see the result.
Curl (stands for Client URL) is a famous command-line tool that developers can you to send requests to the server, upload files, and submit web forms. Curl supports all modern protocols, including HTTP, HTTPS, SFTP, FTP, and has built-in support for SSL, user authentication, and HTTP Cookies. Curl works on Linux, Mac, Windows.
What is HTTP POST?
POST is one of the nine methods of the HTTP protocol. The HTTP POST method requests the webserver to receive and process the data contained in the body of the message. POST method is often used to submit login or contact forms or upload files and images to the server.
Curl POST Request Syntax
curl -X POST [options] [URL]
What is Basic Authentication?
Basic Authentication is an authentication order built into the HTTP protocol to provide the server with a username and password when it makes an HTTP request to protected resources. The client sends HTTP requests with an authorization header that contains the word Basic followed by a space and a base64 encoded username: password string. Basic Authentication is not the most secure method because it can easily decrypt the username and password from base64String. As a security measure, Basic Authentication should only use Basic Authentication using HTTPS/SSL.
How do I post Basic Authentication using Curl?
To post a Curl request with basic authorization credentials, you must use the -u (or --user) command line parameter: --user username: password.
Curl Basic Authentication Example
curl --user "login:password" [URL]
Curl automatically converts the provided login: password pair into a Base64-encoded string and adds an appropriate HTTP header to the request:
"Authorization: Basic bG9naW46cGFzc3dvcmQ="
Example of Basic Authentication Using Curl POST
The general form of a Curl command for making a POST request with Basic Authentication is as follows: