標籤:res login for reg highlight 1.5 運行 pre creat
Allows you to create a custom HTTP request with any method supported by HTTP.
List of Attributes
URL- 請求地址
Method – 要求方法 POST or GET.
EncType – 編碼類別型,指定Content-Type,如"text/html","application/json"等,會重寫 web_add_[auto_]header中定義的Content-Type。
RecContentType – 回應標頭編碼類別型(Content–Type) e.g., text/html, application/x–javascript.
Body – 請求體,不同的應用中,請求體分別通過Body、BodyBinary或者BodyUnicode參數來傳遞
Resource – 指示URL是否屬於資源。1 是;0 不是。設定了這個參數後,RecContentType參數被忽略。
"Resource=1":意味著當前操作與所在指令碼的成功與否關係不大。在下載資源時如果發生錯誤,是當作警告而不是錯誤來處理的;URL是否被下載受“Run-Time Setting—Browser Emulation--Download non-HTML resources” 這個選項的影響。此操作的響應資訊是不做為HTML來解析的。
"Resource=0" :表明此URL是重要的,不受發送請求(RTS)的影響,在需要時也會解析它。
Mode – 錄製層級: HTML or HTTP.
UserAgent – 使用者代理程式,它是一個HTTP頭的名字,用來標識應用程式,通常是瀏覽器,它呈現的是使用者和伺服器的互動。
簡單樣本:
Action(){ //GET 請求web_custom_request("get_login", "URL=http://10.1.102.75:8000/login?user=Milton&pwd=Loveyp", "Method=GET", "Resource=0", "Mode=HTML", "RecContentType=application/json", LAST );//POST 請求提交form資料web_custom_request("post_form_login", "URL=http://10.1.102.75:8000/login", "Method=POST", "Resource=0", "Mode=HTML", "Body=user=Milton&pwd=Loveyp", LAST );//POST 請求提交json資料web_custom_request("post_json_login", "URL=http://10.1.102.75:8000/json_login", "Method=POST", "Resource=0", "Mode=HTML", "EncType=application/json", "Body={\"user\":\"Milton\",\"pwd\":\"Loveyp\"}", LAST );return 0;}
運行後,通過View-》Test Results檢查請求結果
為了測試方便,這裡附上服務端介面代碼,如下:
@csrf_exemptdef login(request): if request.method == "POST": user = request.POST.get("user") pwd = request.POST.get("pwd") else: user = request.GET.get("user") pwd = request.GET.get("pwd") if user == "Milton" and pwd == "Loveyp": msg = { "code": 1000, "msg": "login success! Welcome~~", } else: msg = { "code": -1, "msg": "username or password error,please try again!", } response = JsonResponse(msg) return response@csrf_exemptdef json_login(request): user="" pwd="" if request.method == "POST": print request.body recive=json.loads(request.body) print recive print type(recive) user=recive.get("user") pwd=recive.get("pwd") if user == "Milton" and pwd == "Loveyp": msg = { "code": 1000, "msg": "login success! Welcome~~", } else: msg = { "code": -1, "msg": "username or password error,please try again!", } response = JsonResponse(msg) return response
LoadRunner 函數之 web_custom_request