简体   繁体   中英

How to request curl http and parse the JSON response in shell script?

URL=$(curl -i -X GET -H "Authorization: Basic token=" -H "Cache-Control: no-cache" -H "http://company url:8080/v1/organizations/wiley/environments/api-team-ci1/stats/apis?select=sum(is_error)&timeRange=01/24/2017%2002:00~01/25/2017%2006:00") 

URL should return a JSON response which I need to parse and grab some values. Not even getting response from the curl command; getting only "curl: no URL specified!" error. Please help me and direct as I am trying to do it for the first time.

You're passing the URL as an argument to -H , but it's not a header – remove the -H before the URL:

url=$(curl -i -X GET -H "Authorization: Basic token=" -H "Cache-Control: no-cache" \
"http://company url:8080/v1/organizations/wiley/environments/api-team-ci1/stats/apis?select=sum(is_error)&timeRange=01/24/2017%2002:00~01/25/2017%2006:00")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM