zoukankan      html  css  js  c++  java
  • post请求

    paylod = {"xx":"xxxx",

        "xx":"xxx"}

    r = requests.post("xxxxxxxxxx",  data=paylod)

    print(r.text)

    =======================================

    --json

    paylod = {"xx":"xxxx",

        "xx":"xxx"}

    data_json = dump.json(paylod) # 转json

    r = requests.post("xxxxxxxxxx",  json=data_jaon)

    print(data_json)

    print(r.text)

    ========================================

    # coding:utf-8
    import requests
    # 禅道host地址
    host = "http://127.0.0.1"

    def login(s,username,psw):
        url = host+"/zentao/user-login.html"

        h = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0",
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
            "Accept-Language": "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3",
            "Accept-Encoding": "gzip, deflate",
            "Referer": host+"/zentao/user-login.html",
            # "Cookie":  # 头部没登录前不用传cookie,因为这里cookie就是保持登录的
            "Connection": "keep-alive",
            "Content-Type": "application/x-www-form-urlencoded",
            }

        body1 = {"account": username,
                 "password": psw,
                 "keepLogin[]": "on",
                 "referer":  host+"/zentao/my/"
                }

        # s = requests.session()   不要写死session

        r1 = s.post(url, data=body1, headers=h)
        # return r1.content  # python2的return这个
        return r1.content.decode("utf-8")  # python3

    def is_login_sucess(res):
            if "登录失败,请检查您的用户名或密码是否填写正确。" in res:
                    return False
            elif "parent.location=" in res:
                    return True
            else:
                    return False

    if __name__ == "__main__":
        s = requests.session()
        a = login(s, "admin", "e10adc3949ba59abbe56e057f20f883e")
        result = is_login_sucess(a)
        print("测试结果:%s"%result)

  • 相关阅读:
    IIS5布署MVC3
    操作数数据类型 ntext 对于 max 运算符无效
    iis配置
    IIS取消目录浏览
    mediamind SyncAds
    告诉你如何做网站运营
    xml as3解析
    mediamind 组件
    AIR for androd 笔记
    开发AIR for android 大象游戏合集开发总结
  • 原文地址:https://www.cnblogs.com/yaohu/p/10304016.html
Copyright © 2011-2022 走看看