getwebpage command
Retrieving Web Pages
If you ever need to build an application that retrieves web pages, you can use the GETWEBPAGE command. It connects to a web server, retrieves a given web page, and saves it to a user-specified file.
The program below called WEB.CBL demonstrates the usage of the GETWEBPAGE command. It utilizes a standard data structure called TCPIP-RETURN-CODES. This group level data item will be populated with information from the specific web server you are accessing. TCPIP-RETURN-CODE is a number, while TCPIP-RETURN-MESSAGE is a string. Typically a successful return code for this operation will be zero, and the return message will contain a string describing the number of bytes received for a particular web document.
Here’s a portion of the code for WEB.CBL:
1 TCPIP-RETURN-CODES.
5 TCPIP-RETURN-CODE PIC 9(07).
5 TCPIP-RETURN-MESSAGE PIC X(255).
MOVE `www.deskware.com` TO host_name.
MOVE `/cobol/cobol.htm` TO web_page_name.
MOVE `web.txt` TO file_name.
DISPLAY `<` host_name `>`.
DISPLAY `<` web_page_name `>`.
DISPLAY `<` file_name `>`.
GETWEBPAGE USING host_name web_page_name file_name.
DISPLAY `TCPIP-RETURN-CODES: ` TCPIP-RETURN-CODES.
GOBACK.
The host name in this example is a fully qualified domain name – www.deskware.com. It is also acceptable to specify a raw IP address as the host name argument. The file name argument is used to create a file with the HTML that you are retrieving. The named file is overwritten each time the GETWEBPAGE command is executed.
GETWEBPAGE
Command:
GETWEBPAGE
Syntax:
GETWEBPAGE <hostname> <webpage-path> <webpage-filename>.
Description:
The GETWEBPAGE command connects to hostname using the HTTP protocol, and retrieves the webpage at location webpage-path. This webpage is then written to the file webpage-filename, replacing any previous contents of webpage-filename.
The TCP/IP return code and return message variables are populated with standard TCP/IP return codes and messages after execution of this command. They can be examined after command execution for error-trapping purposes.
Example Usage:
GETWEBPAGE `www.deskware.com` `/index.htm` `DESK.TXT`.
GETWEBPAGE server_var path_var filename_var.
The GETWEBPAGE command requires that the following variable definitions be included in your program:
1 TCPIP-RETURN-CODES.
5 TCPIP-RETURN-CODE PIC 9(07).
5 TCPIP-RETURN-MESSAGE PIC X(255).
Alternatively, include the sample file TCPIP.CPY in your program. This copybook includes these variable definitions.
Command:
GETWEBPAGE
See Also:
GETHOSTNAME, GETHOSTBYNAME
Sample Program:
WEB.CBL