Uses the HTTP/1.0 protocol to emulate a browser and contact a remote or local host. HTML, XML, and SGML pages can be requested from or posted to the remote serve. Page data is returned one tag at a time inside the <MvCALL> loop.
Uses the HTTP/1.0 protocol to emulate a browser and contact a remote or local host. HTML, XML, and SGML pages can be requested from or posted to the remote serve. Page data is returned one tag at a time inside the <MvCALL> loop. When <MvCALL> receives a document, it iterates once for each object (text or tag) that it receives. Several special variables (described below) are created to contain the data and the object properties. NOTE: Additional documentation needs to be added for FILES, CERTFILE, CERTTYPE, TIMEOUT & HEADERS. Attributes
The <MvCALL>...</MvCALL> loop terminates when the entire document has been received, or when an <MvCALLSTOP> (optional) is encountered. If <MvCALLCONTINUE> is encountered, processing start back at the top continuing with the next item. The system variable s.miva_sslavailable will allow the programmer to determine if OpenSSL is available for use by MvCALL, otherwise <MvCALL> can not support the HTTPS (secure HTTP) protocol. Requesting a DocumentTo request a document, set the ACTION attribute to the URL or IP address of the document and set the METHOD attribute to 'GET'. The FIELDS attribute is not required. This example loads external content from another web server into the variable l.return. Example:
<MvCALL ACTION="http://www.content_server.com/incude/xfiles_cast.html" METHOD="GET">
<MvASSIGN NAME = "l.return" VALUE = "{ l.return $ s.callvalue }">
</MvCALL>
Return Objects<MvCALL> retrieves the document as a sequence of tags and text objects. <MvCALL> passes each object to the program one at a time within each loop Consider the following HTML code:
<MvCALL> will split this code into 11 object:
Object PropertiesEach object returned will have different properties based on the type of object returned, tag or text. The properties are specified in system variables below. In both cases these variables are returned:
Use s.callobjecttype within the loop to decide how to process the object. This example skips the tags and just returns the text. Example:<MvCALL ACTION = "g.url" METHOD = "GET">
<MvIF EXPR = "{ s.callobjecttype EQ 'tag'}">
<MvCALLCONTINUE>
</MvIF>
<MvASSIGN NAME = "l.text" VALUE = "{ l.text $ s.callvalue $ ' '}">
</MvCALL>
Text values returned in s.callvalue will contain the actual string of text and white space. Sequences of white space between tags (such as new lines, spaces, and tabs) will be preserved. If the object type is 'tag' and tag is a start-tag, <MvCALL> then further separates the tag into attribute/value pairs. If the object type is 'text' each of these will be set to null. The following properties are available for each tag:
The variables s.callobjectattributeN and s.callobjectvalueN are also available as arrays s.callobjectattribute[N] and s.callobjectvalue[N]. Consider the following example:
<MvCALL> will set the following variables for this 'tag' object: Note: All values, string and numeric, are returned without quotes.
Sometimes an attribute will be specified without an attribute name, as in:
In this case, the attribute name and the attribute value are considered to be the same. In this example, callobjectattribute1 and callobjectvalue1 will each have the value BORDER. This example retrieves all the image path location from a web page. Example:<MvCALL ACTION = "g.url" METHOD = "GET">
<MvIF EXPR = "{ s.callobjecttype EQ 'tag' AND tolower(s.callobjectelement) = 'img'}">
<MvASSIGN NAME="l.posn" VALUE="{ 1 }">
<MvWHILE EXPR="{ l.posn LE s.callobjectnumattributes }">
<MvIF EXPR="{ tolower(s.callobjectattribute[l.posn]) EQ 'src' }">
<MvASSIGN NAME="l.ndx" VALUE="{ l.ndx + 1 }">
<MvASSIGN NAME="images" INDEX="{ l.ndx }" VALUE="{ s.callobjectvalue[l.posn] }">
<MvWHILESTOP>
</MvIF>
<MvASSIGN NAME="l.posn" VALUE="{ l.posn + 1 }">
</MvWHILE>
</MvIF>
</MvCALL>
HeadersWhen it retrieves a document, <MvCALL> also receives HTTP header information sent by the server. This information is stored in the following variables:
The variables s.callreturnheaderN is also available as arrays s.callreturnheader[N]. The following is an example of header data:
Limitations
More ExamplesDisplaying a page from another website site will not resolve any relative links or images. One workaround for this is to put a <BASE> tag in the page being accessed, giving its absolute URL. Another is to put the appropriate <BASE> tag in the output stream that Miva sends to the browser: Example:
<MvCALL ACTION="{ l.url }" METHOD="GET">
<MvIF EXPR="{s.callobjecttype EQ 'tag' AND tolower(s.callobjectelement) EQ '/head'}">
<MvEVAL EXPR="{ '<base href=' $ l.url_root $ ' />' }">
</MvIF>
<MvEVAL EXPR="{s.callvalue}">
</MvCALL>
This example retrieves a web page and displays the raw HTML source code. Example:
<pre>
<MvCALL ACTION="{ l.url }" METHOD="GET">
<MvEVAL EXPR="{ encodeentities(s.callvalue) }">
</MvCALL>
</pre>
Submitting DataThere are two ways to use <MvCALL> to submit data to a CGI program on a server or to another MivaScript program on the same server. These are the GET and POST methods, and are used in the same way as with an HTML form. The receiving program may be written in another other web languages such as, PERL, PHP, ASP, JAVA which must know which method is being used and be set up to process data accordingly. Your calling program only needs to know what values to send and what method to use. Using GETSet the METHOD attribute to 'GET'. The URL specified by ACTION must have the data that is submitted, appended to the string. The data is separated from the URL by a '?' character, and consists of a sequence of 'name=value' pairs separated by ampersands, '&'. For example: http://www.my_isp.com/cgi-bin/prog1?animal1=fish&animal2=dinosaur If the data contains any special characters, such as space, '=', '~', '&', and '+', each field must be URL-encoded. Use the encodeattribute() function to encode each value. The submitted data will be available to the receiving program via the QUERY_STRING CGI environment variable. Here is an example using GET. Notice in the first example, the URL string is formatted exactly like the href attribute in a link. With GET, you can also use the value list syntax for passing arguments to a program: as show in the second example. Example:
<MvCALL ACTION="http://www.my_isp.com/cgi-bin/prog1?animal1=fish&animal2=dinosaur"
METHOD="GET">
... process return values ...
</MvCALL>
OR
<MvCALL ACTION="http://www.my_isp.com/prog3.mv?fish+dinosaur"
METHOD="GET">
...
</MvCALL>
This first method operate exactly like a link in a web page. <a href="http://www.my_isp.com/cgi-bin/prog1?animal1=fish&animal2=dinosaur">Chick here</a> Using POSTIf you use the POST method to submit data, the data is not sent to the server appended to the URL, but rather in the HTTP headers. The format in which the data is received is the same as when GET is used. That is, a sequence of 'name=value' pairs separated by ampersands, '&'. For most application the POST method is preferred. Instead of obtaining the data from the QUERY_STRING variable, the program receiving the data must read it from its standard input. To use this method, set the METHOD attribute of <MvCALL> to 'POST'. The FIELDS attribute should comma delimited contain a list of variables whose names, together with their values, are sent to the URL specified with the ACTION attribute. This example perform the same post but transmits the field variables directly instead of embedding them within the URL. As explained above use the s.callvalue variable to evaluate the response from the server. This very basic code simply displays the document that the CGI program sends back. Example:<MvASSIGN NAME="l.animal1" VALUE="fish"> <MvASSIGN NAME="l.animal2" VALUE="dinosaur"> <MvCALL ACTION="http://www.my_isp.com/cgi-bin/prog2" METHOD="POST" FIELDS="l.animal1,l.animal2"> ... process the response --- <MvEVAL EXPR="{s.callvalue}"> </MvCALL> Running System CommandsMiva adheres to the principle of 'site sandboxing', which means that it will not interfere with the server or other users on the server. For this reason Miva Script does not allow system commands (such as UNIX shell commands) to be run directly from Miva. If you need to run system commands, you may be able to write a CGI program (using PHP, PERL, shell, or another language) that can execute system commands, and use <MvCALL> to call that CGI program. |