码迷,mamicode.com
首页 > Web开发 > 详细

LoadRunner 函数之 web_add_cookie

时间:2016-12-22 11:33:14      阅读:738      评论:0      收藏:0      [点我收藏+]

标签:alt   domain   eth   代码   image   mode   objc   url   als   

技术分享

技术分享

简单示例:

Action()
{
	// 添加cookie
	web_add_cookie("is_login=True;path=/;domain=10.1.102.75");
	// HTTP GET 请求
	web_custom_request("with_cookie",
					   "URL=http://10.1.102.75:8000/cookie",
					   "Method=GET",
					   "Resource=0",
					   "Mode=HTML",
					   "RecContentType=application/json",
					   LAST);

	// 清除cookie
	web_cleanup_cookies();
	// HTTP GET 请求
	web_custom_request("without_cookie",
					   "URL=http://10.1.102.75:8000/cookie",
					   "Method=GET",
					   "Resource=0",
					   "Mode=HTML",
					   "RecContentType=application/json",
					   LAST);
	return 0;
}

运行结果:

技术分享

技术分享

附接口测试实现代码:

def cookie(request):
    username = request.GET.get("user")
    password = request.GET.get("pwd")
    cookie_content = request.COOKIES
    login_flag = cookie_content.get("is_login")
    print login_flag
    if login_flag == "True" or (username == "qa" and password == "4399"):
        msg = {
            "msg": "login success! Welcome~~",
            "recive_cookie": cookie_content
        }
        response = JsonResponse(msg)
        response.set_cookie("is_login", True)
    else:
        msg = {
            "msg": "username or password error,please try again!",
            "recive_cookie": cookie_content
        }
        response = JsonResponse(msg)
        response.set_cookie("is_login", False)

    return response

  

 

LoadRunner 函数之 web_add_cookie

标签:alt   domain   eth   代码   image   mode   objc   url   als   

原文地址:http://www.cnblogs.com/guanfuchang/p/6208710.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!