执行批量curl请求脚本注意事项

通过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需要用引号括起来

相关推荐