How to set custom header values in a curl request?

Published on Aug. 22, 2023, 12:19 p.m.

To set custom header values in a curl request, you can use the -H or --header flag followed by the header value you want to set. Here is an example:

curl -H "Custom-Header-Name: custom-header-value" https://www.example.com/api/endpoint

In this example, we’re using the -H flag to set a custom header with the name Custom-Header-Name and the value custom-header-value. The header will be sent along with the request to the specified endpoint.

If you want to set multiple custom headers, you can use the -H flag multiple times, like this:

curl -H "Custom-Header-Name1: custom-header-value1" -H "Custom-Header-Name2: custom-header-value2" https://www.example.com/api/endpoint

In this example, we’re setting two custom headers with the names Custom-Header-Name1 and Custom-Header-Name2, and their respective values custom-header-value1 and custom-header-value2.

Note that the specific header names and values you need to provide depend on the requirements of the server you are working with. You may need to consult the documentation or contact the server owner for more information on how to format your custom headers properly.

Also, ensure you replace “Custom-Header-Name” and “custom-header-value” with your actual header name and value.

Lastly, keep in mind that some servers may reject requests with certain header values for security reasons, so be sure to follow any guidelines or restrictions provided by the server owner.

Tags: