httpie 模拟一个post 请求,并且只显示返回的body内容

怎样通过httpie 模拟一个post请求,并且只显示body的内容呢?

请先 登录 后评论

2 个回答

小A

比如如下请求的示例:

http -b --form POST http://rnhg.hkplant.net/mobile/wapi/index.php op=login appid=99000809734051 uid=0 password=e10adc3949ba59abbe56e057f20f883e username=15537422878


-b 为只返回body内容,--from POST 模拟一个post请求 ,后面为POST参数,

返回json内容如下:

{

    "code": 0, 

    "msg": "success", 

    "result": {

        "mobile": "15537422878", 

        "parent_id": "289163", 

        "parent_name": "梁亚伟", 

        "realname": "梁朝伟", 

        "regtime": "1478316172", 

        "token": "f8c7f90721c4a2b019fa", 

        "uid": "289166", 

        "user_photo": "http://rnhg.hkplant.net/mobile/themes/tianxin100/images/photo.png"

    }

}

请先 登录 后评论
石天

使用curl 也能达到相同的效果,不过curl实现起来确实有点麻烦。比如,上面请求可以写成

curl  -d  "op=login&appid=99000809734051&uid=0&password=e10adc3949ba59abbe56e057f20f883e&username=15537422878" http://rnhg.hkplant.net/mobile/wapi/index.php

注意curl 的传递的参数只能使用&连接,不能分开,另外,curl 可以模拟useragent 和referer,如:

curl -I --user-agent "NT66.0" http://192.168.16.254 --referer "http://wenda.zuncuang.com"

请先 登录 后评论
  • 2 关注
  • 0 收藏,1051 浏览
  • shitian 提出于 2016-11-09 16:48

相似问题