【发布时间】:2019-10-02 19:48:17
【问题描述】:
我正在设置一个 shell 脚本来为我处理 curl 请求。
API 需要一个 OPTION 请求,然后我才能使用我的数据参数循环所有以下 POST 请求。
有没有人知道我可以如何改进我的代码和语法,以使 OPTIONS 请求发生一次,然后循环 POST 请求。
提前感谢您的任何指点。
我查看了有关 SH 的不同文档并浏览了很多 SO 页面,但到目前为止没有运气
#!/bin/bash
url="https://www.google.com"
options="$(curl -s -X OPTIONS "$url"-H "Accept: */*" -H "Access-Control-Request-Headers: authorization,content-type" -H "Access-Control-Request-Method: POST" -H "DNT: 1" -H "Origin: https://google.com" -H "User-Agent: Generic" -H "cache-control: no-cache")"
for options
do echo "$options" >> outputposts1.csv 2>&1
done
for id in $(< idt.txt);
do
posts="$(curl -v -s -m 5 -X POST -H "Accept: */*" -H "Authorization: long.auth.key" -H "Content-Type: application/json" -H "DNT: 1" -H "Origin: https://google.com" -H "User-Agent: Generic" -H "cache-control: no-cache" "$url" -d '{"profileid": "'"$id"'","content": "json content","programId": "numbers" \n')"
echo "$posts" >> outputposts2.csv 2>&1
sleep 1s
done
OPTIONS 请求应提供 200 状态,以下 POST 请求应提供 201 状态代码。
【问题讨论】:
-
没有我编辑了代码谢谢
-
我想我修好了