如何在.sh文件中调用rest api

问题描述 投票:0回答:2

我正在尝试创建一个脚本来调用rest api端点但我得到“错误的替换”错误。

这是我的脚本:

vi script.sh
echo "welcome to the script"
echo ${"http://web-integ000/sampleProject/getProductList"}

但是当我在命令行执行curl命令时,它工作了。我使用了以下命令

$ curl -H "Accept:application/json" http://web-integ000/sampleProject/getProductList

我得到以下输出:

[ {
  "productId" : "u1604028-5948abd0-0",
  "prodcutName":"H1ACX",
  "calendarDate" : "2017-06-20"
  }
 ]timeStamp:1497968810

如何使用脚本从其余的api获取响应?

linux
2个回答
1
投票

$计算shell命令或环境变量。操作系统本身无法评估URL,因此您应该使用curl命令,例如:

VAR1=${curl ....}

然后,您可以使用该变量,例如回应它。


0
投票

您可以使用简单的curl命令从服务器获取响应,如下所示: -

rest.是

result=$(curl -X GET --header "Accept: */*" "http://localhost:9090/employees")
echo "Response from server"
echo $result
exit

希望它有效!谢谢!

© www.soinside.com 2019 - 2024. All rights reserved.