How do I send Custom Headers with Curl? [JavaScript/AJAX Code]

To add a custom header to Curl, you need to pass the -H "header: value" command line parameter to the Curl request. In this Curl Custom Headers example, we are sending a custom header to the ReqBin echo URL. The target URL is passed as the first parameter, and the custom header is passed as the second parameter to the Curl command. Click Run to execute the Curl Custom Headers example online and see the results. The JavaScript/AJAX code was automatically generated for the Curl Custom Headers example.
How do I send Custom Headers with Curl? [JavaScript/AJAX Code] Run
curl https://reqbin.com/echo/get/json
    -H "X-Powered-By: ReqBin HTTP Client"
Updated: Viewed: 9463 times
JavaScript/AJAX code for Curl Custom Headers example

JavaScript/AJAX code for Curl Custom Headers Example

This JavaScript/AJAX code snippet was generated automatically for the Curl Custom Headers example.
<< Back to the Curl Custom Headers example

What is Curl?

Curl is a popular open-source command-line tool and cross-platform library (libcurl) for transferring data between servers, designed to work without user intervention. Curl can upload or download data using popular protocols including HTTP, HTTPS, SFTP, SCP, and FTP. Curl has built-in support for HTTP Cookies, SSL, proxies, certificate validation, user authentication and works on all modern platforms and hardware, including Linux, Windows, and macOS.

What is HTTP?

HTTP (Hypertext Transfer Protocol) is a protocol for exchanging data between multiple network devices that are used to transfer data between an HTTP client (browser or mobile application) and a server. Now the HTTP protocol is the most popular and primary communication method on the Internet. HTTP is built on messages called "request" and "response" based on the client-server architecture. Devices communicate with each other by sending HTTP requests and receiving HTTP responses.

What is Custom Headers?

HTTP headers allow clients to send information to the server and return data to the client. The headers are usually invisible to the end-user and are only visible to server soft and network administrators. Custom headers are intended to provide additional information related to the current request or response, or for troubleshooting purposes.

How to add Custom Headers using Curl?

Use the -H "header: value" command-line option to add a custom header to Сurl:

Curl Custom Headers Example
curl https://reqbin.com/echo/get/json
   -H "X-Powered-By: ReqBin HTTP Client"

See also

Generate code snippets for JavaScript/AJAX and other programming languages

Convert your Curl Custom Headers request to the PHP, JavaScript/AJAX, Curl/Bash, Python, Java, C#/.NET code snippets using the JavaScript/AJAX code generator.