Printing the response content body when using curl

2020-08-09 06:06发布

问题:

I'm using the command below on ubuntu:

curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"foo":"bar"}'  http://localhost:8888/

The following is the response received:

< HTTP/1.1 200 OK
< Content-Length: 3
< Content-Type: text/html; charset=UTF-8
< Server: TornadoServer/2.1
<
* Connection #0 to host localhost left intact
* Closing connection #0

So my question is; how do I post using curl and print out the response content body?

回答1:

It finally worked for me with this command:

curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"id":100}' http://localhost/api/postJsonReader.do


回答2:

Did you try to replace -d '{"foo":"bar"}' with -d 'foo=bar'? You shouldn't have to do anything special to receive the response content body as long as the request succeeds.



标签: ubuntu curl