LoadRunner 函數之 web_custom_request

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.