Allows you to create a custom HTTP request with any method supported by HTTP.
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_exempt def 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_exempt def 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
