1. Get-mode HTTP request Performance test script
Action () {Web_set_max_html_param_len ("10000"); Web_reg_save_param ("RetCode", "lb=retcode\ ": \"", "rb=\ "", "notfound=warning", last); Lr_start_transaction ("Test"); Web_custom_request ("Test","url=http://127.0.0.1/test?channelno=1&phoneno=12345678912", "Method=get", "resource=0", "referer=", "mode=http", "enctype=txt/html; Charset=utf-8", "body=", last);if(!STRCMP (Lr_eval_string ("{RetCode}"),"000000") {lr_output_message ("successfull, Retcode is:%s", Lr_eval_string ("{RetCode}")); Lr_end_transaction ("Test", Lr_pass); }Else{lr_error_message ("Failed, Retcode is:%s", Lr_eval_string ("{RetCode}")); Lr_end_transaction ("Test", Lr_fail); }return 0;}
2. JSON string request in post format
Action () {Web_reg_save_param ("RetCode", "lb=retcode\ ": \"", "rb=\ "", "notfound=warning", last); Lr_start_transaction ("Test"); Web_add_header ("Content-type","Application/json"); Web_custom_request ("Test", "url=http://127.0.0.1/test", "Method=post", "resource=0", "referer=", "mode=http", "Enctype=application/json; Charset=utf-8", "Reccontenttype=application/json", "body={\ "channelno\": \ "{channelno}\", \ "Phoneno \": 12345678900,\ "createdtime\": \ "{createdtime}\"}", last);if(!STRCMP (Lr_eval_string ("{RetCode}"),"000000") {lr_output_message ("successfull, Retcode is:%s", Lr_eval_string ("{RetCode}")); Lr_end_transaction ("Test", Lr_pass); }Else{lr_error_message ("Failed, Retcode is:%s", Lr_eval_string ("{RetCode}")); Lr_end_transaction ("Test", Lr_fail); }return 0;}
Note: When writing a JSON string, be careful to ensure that the body content is correct, the string must be between \ "\", the parameter name and the parameter value is:, the parameters and parameters separated by commas
3. Web_reg_save_param Function 3.1 Method Introduction
Grammar:
int Web_reg_save_param (const char *paramname, <list of Attributes>, last);
Parameter description:
Üparamname: The parameter name of the dynamic content to be stored
Ülist of Attributes: Other attributes, including: Notfound, LB, RB, Relframeid, Search, ORD, Saveoffset, Convert, Savelen. Property values are not case-sensitive
Notfound: What to do when you can't find what you're looking for in the return message
Notfound=error: An error message is sent when the content to be found is not found in the return message. This is the default value
Notfound=warning: When nothing is found in the return message, only a warning is issued and the script continues to execute without interruption.
LB (left boundary): Returns the leftmost string of information. The property must be, and is case sensitive.
RB (right): Returns the boundary of the message. The property must be, and is case sensitive.
Relframeid: The frame of the page you want to find relative to the URL. This property can be either all or a number, which is optional.
Search: Returns the search scope for the information. Can be Headers,body,noresource,all (default). The nature of the genus is optional.
ORD: A description of the occurrences of the left-bound substring of the first occurrence is what is needed. This property is optional and the default value is 1. If all, stores all the found content.
Saveoffset: When a match is found, the first character is stored in the parameter. The property cannot be a negative number, and the default value is 0.
Savelen: When a match is found, several characters after the offset are stored in the parameter. The default value is-1, which means that the entire string, until the end, is stored in the parameter.
Note: If the left and right borders contain Chinese characters, tick support CharSet to utf-8 in Tool->recording options,advanced
3.2 Common problems and workarounds
msgid:merr-26377
Error message: "Check whether the requested boundaries exist in the response data. Also, if the data you want to save exceeds 1592 bytes, use Web_set_max_html_param_len to increase the parameter size [Msgi D:MERR-26377] ".
Causes of errors and solutions:
ü The right and left boundary values are incorrect: Vuser->scan action for correllations requires correlation information in correlation results, and point Crete rule to view the left-and about associated characters.
ü Position placement error for the associated function: Vuser->scan action for Correllations to switch the script down and double-click in correlation results to have the associated information The cursor is positioned in the scrip where it needs to be associated.
ü The message returned by the server is too long, exceeding the LoadRunner default parameter save Length (1024 bytes), add the following statement before setting the associated statement: Web_set_max_html_param_len ("10000″); (web_set_max_ The Html_param_len function is used to set the length of the HTML string to be saved);
4. Web_custom_request function
This function is a custom HTTP request rule that allows you to freely define the required HTTP GET and POST requests. Features with Web_link (), Web_url (), Web_submit_data () functions
4.1 Method Introduction
Int web_custom_request (const char *requestname, <list of Attributes>,[extrares, <list of Resource Attributes> ;,] last);
return value: Lr_pass (0) represents success, Lr_fail (1) represents failure.
Parameter description:
Ürequestname: The name of the step, the name that is displayed in the tree view in Vugen.
Ülist of Attribute: The following properties are supported:
(1 ) URL: page address
(2 method: How the page is submitted, post, or get.
(3 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", which indicates that this URL is important, is not affected by the Send request (RTS) and resolves it when needed.
(4 ) Referer: The page associated with the current page. If the address of the URL has been explicitly specified, this entry can be omitted.
(5 Mode: Two levels of recording HTML, HTTP.
HTML level--record intuitive HTML actions on the current web interface. Record these actions in step-by-step Web_url, Web_link, Web_image, and Web_submit_form. Vugen only records requests that return an HTML page, and does not process scripts and applications.
The HTTP level--vugen records all requests as web_url directives and does not generate Web_link, web_image, web_submit_form functions. This method is more flexible, but the resulting script is not intuitive.
(6 ) EncType: Encoding type. This parameter gives a content type (Content-type) that specifies the value of the "Content-type" request header when it is played back as a script, such as "text/html". The Web_custom_request function does not process the non-encoded request body. The request body parameter will use the encoding that has been specified. Therefore, if you specify a "EncType" that does not match the HTTP request body, the server-side error is raised. We generally recommend that you do not manually modify the "EncType" value when recording.
Any designation for Enctype overrides the Content-type specified by the Web_add_[auto_]header function. When a enctype= (null value) is specified, no Content-type request header is generated. When Enctype is omitted, any Web_add_[auto_]header function will work. If neither Enctype nor Web_add_[auto_]header is specified, method=post,application/x-www-form-urlencoded will be used as the default value. In other cases, the Content-type request header is not generated.
(7 ) Body: the request body. In different applications, the request body is passed through the body, bodybinary, or Bodyunicode parameters, respectively. The request body can use only one of the parameters, or a series of separate parameters can be used to form a multi-request body. For example:
Web_custom_request (
......
"Bodyunicode=reprice"
"Bodybinary=\\x08\\x00\\xcc\\x02\\x00\\x00"
"Body=.\r\n"
"-dxjjtbw/(. tp?eg:ch/6--\r\n",
last);
In the above code, 3 parameters are used to divide the request body, one is a Unicode segment, one is a binary segment, and the last is a regular string. The final request body is the value that these 3 parameters are concatenated in the order in which they are in the function. There is also a seldom used parameter, Binary. It can also describe the binary request body, but only one request body parameter is allowed in the function. All the request bodies are ASCII characters, ending with null.
A body--that represents a regular, printable string. Cannot represent empty bytes. All characters are represented by a backslash. Note: In the old script, you can see that non-printable characters are encoded in the request body as 16 binary. (For example, "\\x5c"), in which case you must use "Binary=1" to identify it. Null bytes are expressed using "file://0.0.0.0/". Instead, the new script places the request body in separate parameters ("body= ...", "bodybinary= ...", body= ...).
bodybinary--represents a binary code. Non-printable characters are encoded in the request body in a 16-file://xhh/manner. Here HH represents the hexadecimal value. Null bytes are expressed using "file://0.0.0.0/".
bodyunicode--American English, especially Latin utf-16le (Little-endian) encoding. This encoding appends a 0 byte to the end of each character to make the character more readable. But the actual parameters in the Vugen remove all 0 bytes. But before sending it to the Web server, the Web_custom_request function will re-add 0 bytes. For non-printable characters, the use of a DSLR slash indicates that an empty byte cannot be represented.
Note: If the request body is larger than 100K, a variable is used instead of the body parameter. The variables are defined in Lrw_custom_body.h.
(8 Bodyfilepath: The path of the file to be transferred as the request body. It cannot be used with the following properties: Body, or other body property or RAW Body property including Bodybinary,bodyunicode,raw_body_start or Binary=1.
(9 useragent: User agent, which is the name of an HTTP header used to identify an application, usually a browser, that renders the interaction between the user and the server.
For example: Head information user-agent:mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) recognizes IE Browser 6.0 under Window NT. Other user-agent values are used to describe other browsers, or non-browser programs. Typically, all requests in an application use the same user agent, which is specified by the recorder as a runtime parameter (run-time setting-browser emulation-user agent). In any case, even in a simple browser process, it is possible to use non-browser components (such as ActiveX controls) that interact directly with the server, usually with user-agent properties that are different from the browser. Specify "useragent" to indicate that this is a non-browser request. The specified string is used by HTTP header user-agent: In some cases, it also affects the behavior when the script is played back. For example, do not use browser caching, assuming that the specified URL belongs to a resource, and so on. (LoadRunner itself does not check whether the specified string is the same as the value of the browser itself)
(Ten Binary: Binary=1 represents each of the page request body with a file://x/# #形式出现的值 (where "# #" stands for 2 hexadecimal digits), is replaced by a single-byte hexadecimal value. If binary=0 (the default value), all character sequences are simply passed by literal values. Pay attention to the use of double slashes. In the C compiler, a double slash is interpreted as a single slash. If you do not need 0 bytes, a single slash can be used in cases where binary is not equal to 1 (for example, using \x20 instead of file://x20/). If you need 0 bytes, you can only use File://x00/and set "Binary=1", \x00 is logically truncated.
( One contentencoding: Specifies that the request body is encoded using the specified method (gzip or deflate), and the corresponding Content-encoding:http header is sent along with this request. This parameter applies to web_custom_request and Web_submit_data.
Ftpascii:1 uses ASCII mode to handle FTP operations; 0 "uses binary mode.
TargetFrame: The name of the frame in which the current link or resource resides. In addition to the frame's name, you can specify the following parameters:
_blank: Open an empty window.
_parent: Replace the newly changed frame with its ancestor.
_self: Replaces the newly changed frame.
_top: Replaces the entire page.
( reccontenttype: The content type of the response header when recording the script.
such as text/html, Application/x-javascript and so on. When the resource property is not set, it is used to determine whether the destination URL is a resource that can be logged. This property contains the primary and secondary resources. The most frequently used types are text, image application. Minor types vary a lot depending on the resource. For example: reccontenttype=text/html: Represents HTML text. Reccontenttype=application/msword: Indicates that MSWord is currently in use.
( in ) resourcebytelimit: The Limit size of Web page download resources. When the set limit is reached, additional resources cannot be downloaded. Only valid for resources that need to be downloaded. Download process: If the total download size is less than the limit value, the download starts normally. If the set limit value is reached when downloading, the resource size is known (Content-length is specified in the HTTP response header), in which case the download can be completed normally if only one buffer is required. If more than one buffer is needed, or if the resource size is unknown, the download will break and close the current connection. This feature can be used to simulate situations where a user does not wait to navigate to another page when a page download is complete. It is not available in HTTP mode and is not available in concurrent Groups (a zone in the VUser script, where all functions in the zone are executed concurrently). Only applies to sockets playback, WinInet is also not applicable.
( ) Snapshot: The file name of the snapshot.
( ) extraresbasedir: Root URL, placed in the Extrares group.
It is used to parse the relative URL (translator plus: A relative path and an absolute path similar to Windows). The URL can be an absolute path (for example, Http://weather.abc.com/weather/forecast.jsp?locCode=LFPO), or it can be a relative path (for example, "Forecast.jsp?loccode=lfpo"). The true URL is downloaded through an absolute path, so the relative URL path must be parsed using the root path URL. For example, using http://weather.abc.com/weather/as the root path to resolve "Forecast.jsp?loccode=lfpo", the final URL is: http://weather.abc.com/weather /forecast.jsp?loccode=lfpo. If you do not specify "Extraresbasedir", the default root URL is the URL of the main page.
( ) Raw Body:
The request body is passed as a pointer, which points to a string of data. The binary request body can be sent using the Bodybinary property (or by using the Body property, provided "Binary=1" is required). In any case, this approach requires the use of an escape character backslash to convert non-printable characters to ASCII characters. In order to have a simpler way of showing the raw data, the raw body property comes into being, passing pointers to binary data. The pointers are represented using 4 successive sets of parameters, and must be arranged in order:
Raw_body_start pointer to data buffer
(int) Length Raw_body_end
Example:
Char *abc= .../* Pointer to the raw data */
Web_custom_request ("Stepname",
"Url=http://some.url",
"Method=post",
Raw_body_start,
"ABC",
3,
Raw_body_end,
last);
In an app, even if you set the length of the data to 0, the pointer must have a value and cannot be empty. In "Binary=1", you cannot use the syntax above to pass raw data. Data in the data buffer cannot be parameterized. It is also said that any parameter in the buffer (for example, "{Myparam}") cannot be correctly substituted for the corresponding value, but will only be sent in literal values.
Üextrares: Indicates that the following parameter will be the list of Resource attributes.
Ülast: The end of the indicator.
Ülist of Resource Attributes
List of within Resource only when recording options--recording--html-based script--Record Attribu The current script step option is selected TES will be inserted into the code. The non-HTML mechanism in the Web page produces a list of resources, including JavaScript, ActiveX, Java applets, and flash requested by the resource. In the Vugen's recording option, you can set these resources to be recorded in the current operation (this setting by default) or as a separate step.
4.2 FAQs
JSON string in post format error error-26631:http status-code=400 (bad Request) for
Usually send the HTTP request error caused, it is recommended to use the monitoring tool to grasp the packet (WireShark, fiddler, etc.), check the body of the correct case of the field, the use of the format of the symbol is correct, etc. have encountered the assignment used =, should be:
5. lr_eval_string function
Returns the current value of one parameter in the script, and returns the value type: Char
6. Web_add_header function
Add header header information to the following HTTP request
7. References
Http://www.cnblogs.com/Automation_software/p/3482094.html
http://blog.csdn.net/juanmantou/article/details/8291196
Http://www.tuicool.com/articles/aAvyIb
http://blog.csdn.net/yong_sun/article/details/6733096
http://blog.csdn.net/dfbrt56/article/details/3321558
LR Implementation HTTP protocol performance test script