0
I attempt to use Curl to send some data. Here is a most simple example that works:
curl -v -H "Content-type: text/html" 127.0.0.1:1111
I see output like this:
GET / HTTP/1.1
Host: 127.0.0.1:1111
User-Agent: curl/7.49.1
Accept: */*
Content-type: text/html
Content-type is set there in the output. It works. What I want is to input content type using environment variable.
I write this:
HTML='-H "Content-Type: text/html"
Then in the next command I write this:
curl -v $HTML 127.0.0.1:1111
But it failed. I am given this output:
GET / HTTP/1.1
Host: 127.0.0.1:1111
User-Agent: curl/7.49.1
Accept: */*
"Content-Type: text/html"
Curl is not making a real header, it is just loose string. It has quotes around it, and is indent like you can see above. This is different from before and so the command does not work. It is rejected by server as a wrong content type.
I have tried using --header in stead of -H like this:
HTML='--header "Content-Type: text/html"'
This gives a confusing error:
curl: option --header "Content-Type: text/html": is unknown
curl: try 'curl --help' or 'curl --manual' for more information
I am confused. I have seen other messages here from people who want environment variable inside post data, which is a different problem.
I am using zsh and Curl on MAC OS X. I hope my example is simple enough.
Thankyou for your time and help!