how to get curl to output only http response body (json) and no other headers etc

前端 未结 2 735
执念已碎
执念已碎 2021-01-31 01:12

I am using curl in a bash script to fetch the response of a service as below,

response=$(curl -isb -H \"Accept: application/json\" \"http://host:8080/some/resour         


        
相关标签:
2条回答
  • 2021-01-31 01:35
    #!/bin/bash
    
    req=$(curl -s -X GET http://host:8080/some/resource -H "Accept: application/json") 2>&1
    echo "${req}"
    
    0 讨论(0)
  • 2021-01-31 01:52

    You are specifying the -i option:

    -i, --include

    (HTTP) Include the HTTP-header in the output. The HTTP-header includes things like server-name, date of the document, HTTP-version and more...

    Simply remove that option from your command line:

    response=$(curl -sb -H "Accept: application/json" "http://host:8080/some/resource")
    
    0 讨论(0)
提交回复
热议问题