Functions and Directives

Function LoadFromUrl() Professional

Loads a document from a Web server.

The function is deprecated. Use the HttpClient()class instead.

Example: cResult := HttpClient():new( "http://www.alaska-software.com" ):send()

Syntax
LoadFromUrl( <cURL>        , ;
            [<nPortNumber>], ;
            [<nProtocol>]  , ;
            [<cProxyUrl>]  , ;
            [<acByPass> ]  , ;
            [<cMethod>]    , ;
            [<cPostString>], ;
            [<cCookie>],     ;
            [<cAcceptType>], ;
            [@<nStatus>],     ;
            [<bcUserFunc>] ) --> cWebContent | NIL
Parameters
<cURL>
The URL of the document to be loaded. It is a character string that must be formatted in the following way:
[<protocol>://][<username>:<password>@][www.]destination[:<port>][/<target>] 
All elements of the string are optional except the destination. All elements are taken into consideration when the HTTP connection is established. However, some of them may be overridden if other parameters are passed to the function.
<nPortNumber>
This is a numeric value that optionally specifies the port to be used for the connection. Two #define constants exist in the file ASINET.CH which specifiy default port numbers:
Default ports
Constant Description
INTERNET_DEFAULT_HTTP_PORT Used for the HTTP protocol (non-secure communication)
INTERNET_DEFAULT_HTTPS_PORT Used for the HTTPS protocol (secure communication)
The parameter defaults to the default port of the specified protocol. If <nPortNumber> is passed to the function, it overrides the port number encoded in <cURL>.
<nProtocol>
One of the following #define constants listed in ASINET.CH can be used for this parameter:
Communication protocols
Constant Description
INTERNET_COMMUNICATION_PUBLIC *) Selects the HTTP protocol (non-secure communication)
INTERNET_COMMUNICATION_SECURE Selects the HTTPS protocol (secure communication)
  1. default, unless the protocol is specified in
<cProxyUrl>
This optional parameter is a character string containing the name or the IP address of the proxy server to be used for the Internet connection. The default is taken from the operating system's TCP/IP configuration.
Optionally the port at which the proxy server is listening can be specified, for example:
<company.proxy:81>
This will result in a http request perfomed via the proxy company.proxywhich is listening at port 81
<acByPass>
If a proxy server is specified with <cProxyUrl>, all Internet connections are routed via this proxy by default. To bypass the proxy server for certain requests, an array of character strings can be specified with <acByPass>. They contain the IP adresses or names of the servers to be accessed directly without routing a request via the proxy server.
<cMethod>
When <cURL> is a Cgi encoded string, LoadFromUrl() acts as if a HTML form is submitted from a Web browser to a HTTP server. The parameter <cMethod> then specifies how the form is submitted. This is equivalent to the Method attribute of the Html <form> tag and can be set to "GET" or "POST". The default is "GET".

if <cMethod> is set to "POST", the parameter <cPostString> becomes mandatory.

<cPostString>
This parameter is a Cgi encoded String representing the HTML Form to be submitted via the method "POST". It can be created with the GetCgiString() function or must be formatted according to Cgi specifications using this pattern:
Name1=Value1&Name2=Value2&Name3=Value3 
<cCookie>
If a Cookie is to be sent to the http server as part of the request, the Cookie must be specified in the optional parameter <cCookie>. The Cookie is a character string which must have the notation "cCookieName=cCookieValue". The left side of the equal sign represents the Cookie name, the right side is the Cookie value. If cCookie is an empty string, no Cookie will be send with the request.
If the <cCookie> parameter is passed by reference when calling LoadFromUrl(), the parameter contains the Cookie sent by the web server when the function returns. If no Cookie is sent, cCookie contains the empty string.
<cAcceptType>
TBD
<nStatus>
If this parameter was passed by reference it contains the status value sent from the web server with the response.
<bcUserFunc>
<bcUserFunc> is either a code block or a character string containing the name of a user-defined function. If a function name is specified, the function may not be declared STATIC, but if a code block is specified, it can contain a call to a STATIC FUNCTION. The codeblock/function is triggered after a part of the response has been received from the web server. Three parameters are passed to the codeblock or user define function:
The total number of characters that the web server will send as response to the request. If the parameter is equal -1 then the total number of characters is not known.
The number of characters that have already been received from the web server.
A character string containing the chunk that was currently received from the web server.
Return

The function returns the contents of an URL as character string. If the TCP/IP connection fails, the return value is NIL.

Description

This function is used to load the contents of an URL using the HTTP or HTTPS protocol. The latter provides for a secure data exchange between client and HTTP server since data transferred via TCP/IP connections is encrypted. Calling the function with <cURL> as the sole parameter is sufficient in most cases. Special situations, like routing a request via a proxy server or submitting a HTML form, are covered by the remaining parameters.

The return value NIL indicates a connection failure which can have several reasons: The URL does not exist, illegal parameters are passed, the HTTP server is offline or there is no TCP/IP connection at all. If there is no TCP/IP connection but the computer is configured for a dial-up connection via modem, the operating system will open the dial-up dialog to establish a connection.

Examples
Simply retrieve the html content of the web page
#pragma Library( "Asinet10.lib" ) 

PROCEDURE Main() 

   ? LoadFromUrl( "http://www.alaska-software.com" ) 

RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.