miaobug
V2EX  ›  问与答

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

  •  
  •   miaobug · Sep 9, 2016 · 4176 views
    This topic created in 3566 days ago, the information mentioned may be changed or developed.
    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 replies    2016-09-09 12:08:05 +08:00
    xjp
        1
    xjp  
       Sep 9, 2016
    估计是要 application/json
    UnisandK
        2
    UnisandK  
       Sep 9, 2016
    http://requestb.in/
    都发个 post 过去比较一下就可以了
    awanabe
        3
    awanabe  
       Sep 9, 2016
    data=json.dumps(data) 试试
    awanabe
        4
    awanabe  
       Sep 9, 2016
    如果是 python2 而且参数有中文 data=json.dumps(data, ensure_ascii=False, indent=2),
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5876 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 57ms · UTC 06:22 · PVG 14:22 · LAX 23:22 · JFK 02:22
    ♥ Do have faith in what you're doing.