jueves, 10 de diciembre de 2015

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


Example 1
response=$(curl -sb -H "Accept: application/json" "http://host:8080/some/resource")


Example 2

response=$(curl -sb -H "Accept: application/json" "https://www.yakitome.com/api/rest/tts?api_key=Qrq2C4nWqEHpVKgjN1DzVDyiWp5n&voice=Audrey&speed=5&text=hello+world")


http://stackoverflow.com/questions/24254064/how-to-get-curl-to-output-only-http-response-body-json-and-no-other-headers-et

example 3
response=$(curl -sb -H "Accept: application/json" "https://www.yakitome.com/api/rest/tts?api_key=Qrq2C4nWqEHpVKgjN1DzVDyiWp5n&voice=Audrey&speed=5&text=hello+world") && echo $response  | awk '{print $15}'


will echo the desired  value
"https://www.yakitome.com/tts/index/1691985/eJDxuE7zCFGwS/autoplay",
 

A modified version to remove "  and ,


root@asterisk-dominicana:~# response=$(curl -sb -H "Accept: application/json" "https://www.yakitome.com/api/rest/tts?api_key=Qrq2C4nWqEHpVKgjN1DzVDyiWp5n&voice=Audrey&speed=5&text=hello+world") && echo $response | awk '{print $15}' | sed 's/_//' | tr -d , | tr -d '"'

No hay comentarios:

Publicar un comentario