linux 读取图片文件头,linux – 如何使用cURL从文件中读取头文件?

我找到了this.

我写了这个变种:

#!/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

在headers.txt中,我有:

X-PAYPAL-SECURITY-USERID:123

X-PAYPAL-SECURITY-PASSWORD:123

但是当我运行./public/curl.sh时,我没有得到我发送的标题.

我用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

如何在标题部分正确插入变量?

解决方法:

In yourscript line 3:

headers="$headers -H '$line'"

^-- SC2089: Quotes/backslashes will be treated literally.

Use an array.

好的,那就让我们这样做:

#!/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

结果:

{

"method": "PUT",

"uri": "/",

"path": {

"name": "/",

"query": "",

"params": {}

},

"headers": {

"host": "echo.httpkit.com",

"user-agent": "curl/7.35.0",

"accept": "*/*",

"x-paypal-security-userid": "123", //

"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"

}

标签:linux,shell,curl

来源: https://codeday.me/bug/20190825/1714752.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值