V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
miaobug
V2EX  ›  问与答

curl 的 post 请求...难道和 wget 和 python 的 requests 有什么不一样嘛!

  •  
  •   miaobug · 2016-09-09 11:14:54 +08:00 · 3425 次点击
    这是一个创建于 2787 天前的主题,其中的信息可能已经有所发展或是发生改变。
    import requests
    data = {'username':'xxxxxxxxxx', 'password':'xxxxxxxxxx', 'iprange':'no'}
    r = requests.post("https://xxx.edu.cn/cas/webLogin",data=data)
    

    可以用

    wget --post-data "username=xxxxxxxxxx&password=xxxxxxxxxx&iprange=no" https://xxx.edu.cn/cas/webLogin
    

    也可以用

    curl -X POST -D "username=xxxxxxxxxx&password=xxxxxxxxxx&iprange=no" https://xxx.edu.cn/cas/webLogin
    curl -X POST -H "Content-Type:application/x-www-form-urlencoded" -D "username=xxxxxxxxxx&password=xxxxxxxxxx&iprange=no" https://xxx.edu.cn/cas/webLogin
    curl -X POST -F "name=xxxxxxxx" -F passwd="xxx" -F ... https://xxx.edu.cn/cas/webLogin
    

    这些格式怎么都不行... 请老司机指点!

    4 条回复    2016-09-09 12:08:05 +08:00
    xjp
        1
    xjp  
       2016-09-09 11:50:03 +08:00
    估计是要 application/json
    UnisandK
        2
    UnisandK  
       2016-09-09 12:02:40 +08:00
    http://requestb.in/
    都发个 post 过去比较一下就可以了
    awanabe
        3
    awanabe  
       2016-09-09 12:07:22 +08:00
    data=json.dumps(data) 试试
    awanabe
        4
    awanabe  
       2016-09-09 12:08:05 +08:00
    如果是 python2 而且参数有中文 data=json.dumps(data, ensure_ascii=False, indent=2),
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2983 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 08:45 · PVG 16:45 · LAX 01:45 · JFK 04:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.