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 POST request online and see the result. The Java code was automatically generated for the Curl POST Basic Authentication example.
Curl (stands for Client URL) is popular command-line tool developers use 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 standard methods of the HTTP protocol. The HTTP POST method requests the webserver to receive and process the data contained in the body of the POST message. POST method is often used to submit login or contact forms and upload files and images to the server.
Curl POST Request Syntax
curl -X POST [options] [URL]
What is Basic Authentication?
Basic Authentication is a client authentication method built into the HTTP protocol that allows a client to provide a username and password to the server when accessing secure resources over HTTP. When requesting a protected resource, 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 other protocol sniffers can easily decrypt base64 encoded user credentials. For security reasons, the Basic Authentication method should only be used over secure HTTPS/SSL connections.
How do I post Basic Authentication data using Curl?
To post a Curl request with Basic Authorization credentials, you can use the -u (or --user) command line parameter: --user username: password.
Curl Basic Authentication Request 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 user Authentication using Curl POST request
The general form of a Curl command for making a POST request with Basic Authentication is as follows:
Curl POST Request with Basic Authentication Example