2011-10-23 69 views
13

打印時的響應內容主體:使用curl後我用下面的命令在Ubuntu上數據

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

以下是收到的響應:

< 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 

所以我的問題是;如何使用curl發佈並打印響應內容主體?

回答

14

它最後用這個命令爲我工作:

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

終於來了!只需設置「接受」標題就可以做到...... – AlonL

+0

^取決於另一端的服務。 –

0

您是否試圖用-d 'foo=bar'替換-d '{"foo":"bar"}'?只要請求成功,您就不需要做任何特殊的事情來接收響應內容主體。