web_convert_param
Converts HTML to a URL or plain text.
int web_convert_param( const char *ParamName, [char *SourceString] char *SourceEncoding, char *TargetEncoding, LAST );
Argument | Description |
|---|---|
ParamName | The name of a parameter. The converted string will be saved in this parameter. If SourceString is not used, it initially contains the text to convert. Note that this is not a name–value pair. Pass only the name of the parameter. |
SourceString | A literal string to convert. "SourceString=your text" |
SourceEncoding | The encoding type of the source data: HTML, URL, or plain text, in the format: "SourceEncoding=HTML" "SourceEncoding=URL" or"SourceEncoding=PLAIN" |
TargetEncoding | The target data format: URL, HTML, or plain text, in the format: "TargetEncoding=URL"or"TargetEncoding=PLAIN" |
LAST | A marker indicating the end of the argument list. |
Return Values
This function returns LR_PASS (0) on success, and LR_FAIL (1) on failure.
Parameterization
Standard Parameterization may be used for the Source and Target arguments.
General Information
The web_convert_param function either converts HTML text to plain text or URL, or converts plain text to URL.
If SourceString is not passed, the text in parameter ParamName is converted and the result overwrites the parameter value. If SourceString is passed, the source string is converted and stored in parameter ParamName.
SourceString can contain parameters. The source string is first evaluated, replacing parameters with their values, then converted. The result is stored in parameter ParamName.
HTML format uses codes for some non–alphanumerical characters, such as & for ampersand. URLs do not support non–alpha–numerical characters and use the escape sequence %number to represent them. To use an HTML value in a URL, you must therefore convert it into an escape sequence or plain text. For example, an ampersand is represented in a URL as %26. When you use this function to convert the HTML to plain text, it converts it to the way the character would appear in a browser.
The following table shows the same content in HTML, URL, and plain text formats:
HTML | URL | Plain Text |
|---|---|---|
<mytag>& |
%3Cmytag%3E%26 |
<mytag>& |
This function is useful when you retrieve a URL from an HTML document, and you want to use it in an HTTP request such as web_custom_request.
Example
In Example 1, web_convert_param converts HTML strings to URL and plain text formats.
Example 2 shows the use of the SourceString argument.
Example 1
The following example uses web_convert_param to convert HTML strings to URL and plain text formats.
The web page has these texts:
Sample HTML code to be converted: <mytag>& End
Sample plain text to be converted: 1–AD X=0+2 End
Action()
{
web_reg_save_param("HTML",
"LB=Sample HTML code to be converted: ",
"RB= End",
LAST );
web_reg_save_param("HTML1",
"LB=Sample HTML code to be converted: ",
"RB= End",
LAST );
web_reg_save_param("Plaintext",
"LB=Sample plain text to be converted: ",
"RB= End",
LAST );
web_url("web_url",
"URL=http://lazyboy/html/convert_param_page.html",
"TargetFrame=",
"Resource=0",
"Referer=",
LAST );
web_convert_param("HTML", "SourceEncoding=HTML",
"TargetEncoding=URL", LAST );
web_convert_param("HTML1", "SourceEncoding=HTML",
"TargetEncoding=PLAIN", LAST );
web_convert_param("Plaintext", "SourceEncoding=HTML",
"TargetEncoding=URL", LAST );
web_reg_save_param("Result",
"LB=<code>entry = ",
"RB=</code>",
LAST );
web_custom_request("web_custom_request",
"URL=http://lazarus/cgi–bin/post_query.exe",
"Method=POST",
"TargetFrame=",
"Resource=0",
"Referer=",
"Body=entry={Plaintext},{HTML}",
LAST );
return 0;
}
The following section shows the relevant sections of the log file that resulted from running the above segment:
Running Vuser...
Action.c(21): Saving Parameter "HTML = <mytag>&"
Action.c(21): Saving Parameter "HTML1 = <mytag>&"
Action.c(21): Saving Parameter "Plaintext = 1–AD X=0+2"
After web_url:
Action.c(28): Saving Parameter "HTML = %3Cmytag%3E%26"
Action.c(28): web_convert_param was successful
Action.c(29): Saving Parameter "HTML1 = <mytag>&"
Action.c(29): web_convert_param was successful
Action.c(30): Saving Parameter "Plaintext = 1–AD+X%3D0%2B2"
Action.c(30): web_convert_param was successful
web_custom_request:
Action.c(37): Parameter Substitution: parameter "Plaintext" = "1–AD+X%3D0%2B2"
Action.c(37): Parameter Substitution: parameter "HTML" = "%3Cmytag%3E%26"
Action.c(37): Saving Parameter "Result = 1–AD X=0+2,<mytag>&"
Example 2
This example shows the use of the SourceString argument. Note that the source string can contain parameters. The source string is first evaluated, replacing parameters with their values, then converted to PLAIN. The result is stored in parameter "targetParam."
web_convert_param(
"targetParam",
"SourceString={param1}abc{param2}",
"SourceEncoding=HTML",
"TargetEncoding=PLAIN",
LAST );

