curl: read headers from file

Since curl 7.55.0

Easy:

$ curl -H @header_file https://example.com

… where the header file is a plain text file with an HTTP header on each line. Like this:

Color: red
Shoesize: 11
Secret: yes
User-Agent: foobar/3000
Name: "Joe Smith"

Before curl 7.55.0

curl had no way to bulk change headers like that from a file. They had to be modified one bye one with -H.

Your best approach with an old curl version is probably to instead write a shell script that gathers all the headers from the file and use them, like:

#!/bin/sh
while read line; do
  args="$args -H '$line'";
done
curl $args https://example.com

Invoke the script like this:

$ sh script.sh < header_file

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)