How to read headers from file using cURL?
I found this.
And I wrote this variant:
#!/bin/bash
while read line ; do
headers="$headers -H '$line'"
done < public/headers.txt
echo $headers
curl -X PUT
$headers
-d @'public/example.json'
echo.httpkit.com
In headers.txt
I have:
X-PAYPAL-SECURITY-USERID:123
X-PAYPAL-SECURITY-PASSWORD:123
But when I run ./public/curl.sh
I am not getting the headers I am sending.
I isolated the issue with an env var:
$ x='-H some:asd'
$ curl $x echo.httpkit.com
=> header was NOT present
$ curl -H 'some:asd' echo.httpkit.com
=> header was present
$ curl -H some:asd echo.httpkit.com
=> header was present
How can I correctly insert a variable in the header section?
linux shell curl
add a comment |
I found this.
And I wrote this variant:
#!/bin/bash
while read line ; do
headers="$headers -H '$line'"
done < public/headers.txt
echo $headers
curl -X PUT
$headers
-d @'public/example.json'
echo.httpkit.com
In headers.txt
I have:
X-PAYPAL-SECURITY-USERID:123
X-PAYPAL-SECURITY-PASSWORD:123
But when I run ./public/curl.sh
I am not getting the headers I am sending.
I isolated the issue with an env var:
$ x='-H some:asd'
$ curl $x echo.httpkit.com
=> header was NOT present
$ curl -H 'some:asd' echo.httpkit.com
=> header was present
$ curl -H some:asd echo.httpkit.com
=> header was present
How can I correctly insert a variable in the header section?
linux shell curl
How do you know the header is present or not? I'm checking withcurl -v $x echo.httpkit.com 2>&1 >/dev/null | grep some:
and it matches, looks like the header is there just fine. What is your ``curl --version` ?
– janos
Jul 2 '14 at 22:16
add a comment |
I found this.
And I wrote this variant:
#!/bin/bash
while read line ; do
headers="$headers -H '$line'"
done < public/headers.txt
echo $headers
curl -X PUT
$headers
-d @'public/example.json'
echo.httpkit.com
In headers.txt
I have:
X-PAYPAL-SECURITY-USERID:123
X-PAYPAL-SECURITY-PASSWORD:123
But when I run ./public/curl.sh
I am not getting the headers I am sending.
I isolated the issue with an env var:
$ x='-H some:asd'
$ curl $x echo.httpkit.com
=> header was NOT present
$ curl -H 'some:asd' echo.httpkit.com
=> header was present
$ curl -H some:asd echo.httpkit.com
=> header was present
How can I correctly insert a variable in the header section?
linux shell curl
I found this.
And I wrote this variant:
#!/bin/bash
while read line ; do
headers="$headers -H '$line'"
done < public/headers.txt
echo $headers
curl -X PUT
$headers
-d @'public/example.json'
echo.httpkit.com
In headers.txt
I have:
X-PAYPAL-SECURITY-USERID:123
X-PAYPAL-SECURITY-PASSWORD:123
But when I run ./public/curl.sh
I am not getting the headers I am sending.
I isolated the issue with an env var:
$ x='-H some:asd'
$ curl $x echo.httpkit.com
=> header was NOT present
$ curl -H 'some:asd' echo.httpkit.com
=> header was present
$ curl -H some:asd echo.httpkit.com
=> header was present
How can I correctly insert a variable in the header section?
linux shell curl
linux shell curl
edited Nov 22 '18 at 7:59
jww
53.4k40231506
53.4k40231506
asked Jul 2 '14 at 21:32
juanpastasjuanpastas
15.6k1167126
15.6k1167126
How do you know the header is present or not? I'm checking withcurl -v $x echo.httpkit.com 2>&1 >/dev/null | grep some:
and it matches, looks like the header is there just fine. What is your ``curl --version` ?
– janos
Jul 2 '14 at 22:16
add a comment |
How do you know the header is present or not? I'm checking withcurl -v $x echo.httpkit.com 2>&1 >/dev/null | grep some:
and it matches, looks like the header is there just fine. What is your ``curl --version` ?
– janos
Jul 2 '14 at 22:16
How do you know the header is present or not? I'm checking with
curl -v $x echo.httpkit.com 2>&1 >/dev/null | grep some:
and it matches, looks like the header is there just fine. What is your ``curl --version` ?– janos
Jul 2 '14 at 22:16
How do you know the header is present or not? I'm checking with
curl -v $x echo.httpkit.com 2>&1 >/dev/null | grep some:
and it matches, looks like the header is there just fine. What is your ``curl --version` ?– janos
Jul 2 '14 at 22:16
add a comment |
2 Answers
2
active
oldest
votes
Let's ask shellcheck:
In yourscript line 3:
headers="$headers -H '$line'"
^-- SC2089: Quotes/backslashes will be treated literally.
Use an array.
Ok, then let's do that:
#!/bin/bash
while read line ; do
headers=("${headers[@]}" -H "$line")
done < public/headers.txt
echo "${headers[@]}"
curl -X PUT
"${headers[@]}"
-d @'public/example.json'
echo.httpkit.com
Result:
{
"method": "PUT",
"uri": "/",
"path": {
"name": "/",
"query": "",
"params": {}
},
"headers": {
"host": "echo.httpkit.com",
"user-agent": "curl/7.35.0",
"accept": "*/*",
"x-paypal-security-userid": "123", // <----- Yay!!
"x-paypal-security-password": "123",
"content-length": "32",
"content-type": "application/x-www-form-urlencoded"
},
"body": ""This is text from example.json"",
"ip": "127.0.0.1",
"powered-by": "http://httpkit.com",
"docs": "http://httpkit.com/echo"
}
great answer! thanks a lot
– juanpastas
Jul 3 '14 at 3:06
add a comment |
If you don't want to put the HTTP headers on a command line (perhaps for security reasons), you can still have curl read them directly from a file.
curl -H @headerfile.txt https://www.google.com/ # requires curl >=7.55.0
If your curl is older than 7.55.0:
- Use the option
-K/--config <config file>
, and put several-H/--header <header>
lines in the text file.
For more details, please see my answer in the original article:
https://stackoverflow.com/a/48762561/5201675
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24541379%2fhow-to-read-headers-from-file-using-curl%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Let's ask shellcheck:
In yourscript line 3:
headers="$headers -H '$line'"
^-- SC2089: Quotes/backslashes will be treated literally.
Use an array.
Ok, then let's do that:
#!/bin/bash
while read line ; do
headers=("${headers[@]}" -H "$line")
done < public/headers.txt
echo "${headers[@]}"
curl -X PUT
"${headers[@]}"
-d @'public/example.json'
echo.httpkit.com
Result:
{
"method": "PUT",
"uri": "/",
"path": {
"name": "/",
"query": "",
"params": {}
},
"headers": {
"host": "echo.httpkit.com",
"user-agent": "curl/7.35.0",
"accept": "*/*",
"x-paypal-security-userid": "123", // <----- Yay!!
"x-paypal-security-password": "123",
"content-length": "32",
"content-type": "application/x-www-form-urlencoded"
},
"body": ""This is text from example.json"",
"ip": "127.0.0.1",
"powered-by": "http://httpkit.com",
"docs": "http://httpkit.com/echo"
}
great answer! thanks a lot
– juanpastas
Jul 3 '14 at 3:06
add a comment |
Let's ask shellcheck:
In yourscript line 3:
headers="$headers -H '$line'"
^-- SC2089: Quotes/backslashes will be treated literally.
Use an array.
Ok, then let's do that:
#!/bin/bash
while read line ; do
headers=("${headers[@]}" -H "$line")
done < public/headers.txt
echo "${headers[@]}"
curl -X PUT
"${headers[@]}"
-d @'public/example.json'
echo.httpkit.com
Result:
{
"method": "PUT",
"uri": "/",
"path": {
"name": "/",
"query": "",
"params": {}
},
"headers": {
"host": "echo.httpkit.com",
"user-agent": "curl/7.35.0",
"accept": "*/*",
"x-paypal-security-userid": "123", // <----- Yay!!
"x-paypal-security-password": "123",
"content-length": "32",
"content-type": "application/x-www-form-urlencoded"
},
"body": ""This is text from example.json"",
"ip": "127.0.0.1",
"powered-by": "http://httpkit.com",
"docs": "http://httpkit.com/echo"
}
great answer! thanks a lot
– juanpastas
Jul 3 '14 at 3:06
add a comment |
Let's ask shellcheck:
In yourscript line 3:
headers="$headers -H '$line'"
^-- SC2089: Quotes/backslashes will be treated literally.
Use an array.
Ok, then let's do that:
#!/bin/bash
while read line ; do
headers=("${headers[@]}" -H "$line")
done < public/headers.txt
echo "${headers[@]}"
curl -X PUT
"${headers[@]}"
-d @'public/example.json'
echo.httpkit.com
Result:
{
"method": "PUT",
"uri": "/",
"path": {
"name": "/",
"query": "",
"params": {}
},
"headers": {
"host": "echo.httpkit.com",
"user-agent": "curl/7.35.0",
"accept": "*/*",
"x-paypal-security-userid": "123", // <----- Yay!!
"x-paypal-security-password": "123",
"content-length": "32",
"content-type": "application/x-www-form-urlencoded"
},
"body": ""This is text from example.json"",
"ip": "127.0.0.1",
"powered-by": "http://httpkit.com",
"docs": "http://httpkit.com/echo"
}
Let's ask shellcheck:
In yourscript line 3:
headers="$headers -H '$line'"
^-- SC2089: Quotes/backslashes will be treated literally.
Use an array.
Ok, then let's do that:
#!/bin/bash
while read line ; do
headers=("${headers[@]}" -H "$line")
done < public/headers.txt
echo "${headers[@]}"
curl -X PUT
"${headers[@]}"
-d @'public/example.json'
echo.httpkit.com
Result:
{
"method": "PUT",
"uri": "/",
"path": {
"name": "/",
"query": "",
"params": {}
},
"headers": {
"host": "echo.httpkit.com",
"user-agent": "curl/7.35.0",
"accept": "*/*",
"x-paypal-security-userid": "123", // <----- Yay!!
"x-paypal-security-password": "123",
"content-length": "32",
"content-type": "application/x-www-form-urlencoded"
},
"body": ""This is text from example.json"",
"ip": "127.0.0.1",
"powered-by": "http://httpkit.com",
"docs": "http://httpkit.com/echo"
}
edited Jul 2 '14 at 22:49
answered Jul 2 '14 at 22:44
that other guythat other guy
73.6k885123
73.6k885123
great answer! thanks a lot
– juanpastas
Jul 3 '14 at 3:06
add a comment |
great answer! thanks a lot
– juanpastas
Jul 3 '14 at 3:06
great answer! thanks a lot
– juanpastas
Jul 3 '14 at 3:06
great answer! thanks a lot
– juanpastas
Jul 3 '14 at 3:06
add a comment |
If you don't want to put the HTTP headers on a command line (perhaps for security reasons), you can still have curl read them directly from a file.
curl -H @headerfile.txt https://www.google.com/ # requires curl >=7.55.0
If your curl is older than 7.55.0:
- Use the option
-K/--config <config file>
, and put several-H/--header <header>
lines in the text file.
For more details, please see my answer in the original article:
https://stackoverflow.com/a/48762561/5201675
add a comment |
If you don't want to put the HTTP headers on a command line (perhaps for security reasons), you can still have curl read them directly from a file.
curl -H @headerfile.txt https://www.google.com/ # requires curl >=7.55.0
If your curl is older than 7.55.0:
- Use the option
-K/--config <config file>
, and put several-H/--header <header>
lines in the text file.
For more details, please see my answer in the original article:
https://stackoverflow.com/a/48762561/5201675
add a comment |
If you don't want to put the HTTP headers on a command line (perhaps for security reasons), you can still have curl read them directly from a file.
curl -H @headerfile.txt https://www.google.com/ # requires curl >=7.55.0
If your curl is older than 7.55.0:
- Use the option
-K/--config <config file>
, and put several-H/--header <header>
lines in the text file.
For more details, please see my answer in the original article:
https://stackoverflow.com/a/48762561/5201675
If you don't want to put the HTTP headers on a command line (perhaps for security reasons), you can still have curl read them directly from a file.
curl -H @headerfile.txt https://www.google.com/ # requires curl >=7.55.0
If your curl is older than 7.55.0:
- Use the option
-K/--config <config file>
, and put several-H/--header <header>
lines in the text file.
For more details, please see my answer in the original article:
https://stackoverflow.com/a/48762561/5201675
answered Feb 13 '18 at 9:01
traaltraal
8615
8615
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24541379%2fhow-to-read-headers-from-file-using-curl%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
How do you know the header is present or not? I'm checking with
curl -v $x echo.httpkit.com 2>&1 >/dev/null | grep some:
and it matches, looks like the header is there just fine. What is your ``curl --version` ?– janos
Jul 2 '14 at 22:16