curl批量调用linux,执行批量curl请求脚本注意事项

本文档描述了一个使用Shell脚本通过awk命令生成并批量执行curl请求时遇到的问题。当尝试批量执行curl命令时,出现了HTTP Status 400错误,提示所需参数'token'未提供。问题的根源在于URL没有被正确地引号包围。通过在URL外添加双引号解决了该问题,使得批量执行的curl请求能够正常工作。这个案例强调了在构建命令行字符串时正确处理特殊字符的重要性。
摘要由CSDN通过智能技术生成

通过shell生成curl请求 然后批量执行 如下所示

awk -F, 'NR>1{print $(NF-1)}' orders | awk '{print "curl http://localhost:8080/orders?orderSeq="$0"&token=a059a61d7e9211e6a22b4437e6d0648e"}'

curl http://localhost:8080/orders?orderSeq=1234567890&token=a059a61d7e9211e6a22b4437e6d0648e

awk -F, 'NR>1{print $(NF-1)}' orders | awk '{print "curl http://localhost:8080/orders?orderSeq="$0"&token=a059a61d7e9211e6a22b4437e6d0648e"}' | sh

#但是报错

HTTP Status 400 - Required String parameter 'token' is not present

# 奇怪 终端上执行单个请求是可以的

curl http://localhost:8080/orders\?orderSeq\=1234567890\&token\=a059a61d7e9211e6a22b4437e6d0648e

order 1234567890 not exist

解决方法

给url加上双引号即可

awk -F, 'NR>1{print $(NF-1)}' orders | awk '{print "curl \"http://localhost:8080/orders?orderSeq="$0"&token=a059a61d7e9211e6a22b4437e6d0648e\""}'

curl "http://localhost:8080/temp/sendCoupons?orderSeq=1234567890&token=a059a61d7e9211e6a22b4437e6d0648e"

总结

批量执行curl请求 url需要用引号括起来

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值