Allows-Create a custom HTTP request with any method supported by HTTP.
List of Attributes
url-Request Address
Method – Request methods POST or GET.
EncType – The encoding type, specifying Content-type, such as "text/html", "Application/json", and so on, overrides the Web_add_[auto_]header defined in Content-type.
Reccontenttype – Response header encoding type (content–type) e.g., text/html, application/x–javascript.
body– request body, different applications, the request body through the body, bodybinary or Bodyunicode parameters to pass
Resource – Indicates whether the URL belongs to a resource. 1 Yes; 0 is not. When this parameter is set, the Reccontenttype parameter is ignored.
"resource=1": means that the current operation has little to do with the success of your script. If an error occurs while downloading a resource, it is treated as a warning rather than an error, and the URL is downloaded by the "Run-time Setting-browser emulation--download non-html resources" option. The response information for this operation is not parsed as HTML.
"Resource=0": Indicates that this URL is important, is not affected by the Send request (RTS), and resolves it when needed.
Mode – recording level: HTML or HTTP.
useragent– User agent, which is the name of an HTTP header that identifies an application, usually a browser, that renders the interaction between the user and the server.
Simple example:
Action () { //get request 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 request to submit form data 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 Request to submit JSON data 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;}
After running, check the request result through view-"test results
For testing convenience, here is the server interface code, as follows:
@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": +, "msg": "Logi N success! Welcome~~ ",} else:msg = {" Code ":-1," MSG ":" Username or password error,please t Ry 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 Reciv e print type (recive) user=recive.get ("User") Pwd=recive.get ("pwd") if user = = "Milton" and pwd = = "LOVEYP": Msg = {"Code": +, "MSG": "Login success! Welcome~~ ",} else:msg = {" Code ":-1," MSG ":"Username or password error,please try again! ",} response = Jsonresponse (msg) return response
The Web_custom_request of LoadRunner function