linux - Bash Linux Curl 从变量发送 header

标签 linux bash curl header

我有一些 bash 脚本。 我想用一些 header (cloudflare block :) 向服务器发送请求。

我是这样写的:

headers="\
-H 'Host: somesite.com' \
-H 'Accept-Language: pl,en-US;q=0.7,en;q=0.3' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
-H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'DNT: 1' \
-H 'Connection: keep-alive'";

curl $headers somesite.com

但在输出中我有这个..

curl: (6) Couldn't resolve host 'Accept-Language'
curl: (6) Couldn't resolve host 'pl,en-US;q=0.7,en;q=0.3'
curl: (6) Couldn't resolve host 'Accept'
curl: (6) Couldn't resolve host 'text'
curl: (6) Couldn't resolve host 'User-Agent'
curl: (6) Couldn't resolve host 'Mozilla'
curl: (6) Couldn't resolve host '(Windows'
curl: (6) Couldn't resolve host 'NT'
curl: (6) Couldn't resolve host '6.1;'

如何将标题从变量放入命令?

最佳答案

不要为此使用字符串。尝试在这样的字符串中正确引用基本上是不可能的,请使用数组。

参见 http://mywiki.wooledge.org/BashFAQ/050了解更多。

关于linux - Bash Linux Curl 从变量发送 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26577236/

相关文章:

linux - 如何在 Linux 机器上编写 Flash ActionScript ?

linux - 我正在使用 rsync 将所有 httpdocs 文件从服务器复制到服务器,我用什么来包含隐藏/htaccess 文件

linux - Shell 脚本 - 无回显且无错误

curl 替换 'wget -O' 或如何使用 curl 定义目标文件

python - 如何从/dev/input/mice 读出滚轮信息?

linux - 如何将 linux 系统文件覆盖到 yocto 文件系统中?

linux - 为什么在使用 Vagrant shell 脚本配置 Ubuntu VM 期间不执行脚本?

bash - 如何将一个文件连接到多个文件?

php - 如何使用 PHP 简单的 HTML DOM 解析器获取标签的属性

linux - curl ftp上传文件权限