Next: , Previous: , Up: Networking Utilities   [Contents][Index]


36.4.2 WWW Access

Octave can communicate with websites across the Internet. The web function will launch an external web browser to interactively view a site. The remaining functions—urlread, urlwrite, webread, webwrite—are internal Octave functions which can import or export data to/from Octave and a website identified by a URL (Uniform Resource Locator).

: status = web ()
: status = web (url)
: status = web (url, option)
: status = web (url, option_1, …, option_N)
: [status, h, url] = web (…)

Open url in the default system web browser.

With no arguments given, the address https://www.octave.org is opened.

Additional options can be passed for MATLAB compatibility, but are ignored.

The return value status has one of the values:

The return values handle and url are currently unimplemented but given for compatibility.

See also: weboptions, webread, webwrite, urlread, urlwrite.

: s = urlread (url)
: [s, success] = urlread (url)
: [s, success, message] = urlread (url)
: […] = urlread (url, method, param)

Download a remote file specified by its url and return its content in string s.

For example:

s = urlread ("ftp://ftp.octave.org/pub/README");

The variable success is 1 if the download was successful, otherwise it is 0 in which case message contains an error message.

If no output argument is specified and an error occurs, then the error is signaled through Octave’s error handling mechanism.

This function uses libcurl. Curl supports, among others, the HTTP, FTP, and FILE protocols. Username and password may be specified in the URL. For example:

s = urlread ("http://user:password@example.com/file.txt");

GET and POST requests can be specified by method and param. The parameter method is either ‘get’ or ‘post’ and param is a cell array of parameter and value pairs. For example:

s = urlread ("http://www.google.com/search", "get",
            {"query", "octave"});

See also: urlwrite.

: urlwrite (url, localfile)
: f = urlwrite (url, localfile)
: [f, success] = urlwrite (url, localfile)
: [f, success, message] = urlwrite (url, localfile)

Download a remote file specified by its url and save it as localfile.

For example:

urlwrite ("ftp://ftp.octave.org/pub/README",
          "README.txt");

The full path of the downloaded file is returned in f.

The variable success is 1 if the download was successful, otherwise it is 0 in which case message contains an error message.

If no output argument is specified and an error occurs, then the error is signaled through Octave’s error handling mechanism.

This function uses libcurl. Curl supports, among others, the HTTP, FTP, and FILE protocols. Username and password may be specified in the URL, for example:

urlwrite ("http://username:password@example.com/file.txt",
          "file.txt");

GET and POST requests can be specified by method and param. The parameter method is either ‘get’ or ‘post’ and param is a cell array of parameter and value pairs. For example:

urlwrite ("http://www.google.com/search", "search.html",
          "get", {"query", "octave"});

See also: urlread.

: response = webread (url)
: response = webread (url, name1, value1, …)
: response = webread (…, options)

Read content from RESTful web service.

Read content from the web service specified by url and return the content in response.

All key-value pairs given (name1, value1, …) are appended as query parameters to url. To place a query in the body of the message, use webwrite. The web service defines the acceptable query parameters.

options is a weboptions object that may be used to add other HTTP request options. This argument can be used with either calling form. See help weboptions for a complete list of supported HTTP options.

See also: weboptions, webwrite.

: response = webwrite (url, name1, value1, …)
: response = webwrite (url, data)
: response = webwrite (…, options)

Write data to RESTful web services.

Write content to the web service specified by url and return the response in response.

All key-value pairs given (name1, value1, …) are added as pairs of query parameters to the body of request method (get, post, put, etc.).

options is a weboptions object that may be used to add other HTTP request options. This argument can be used with either calling form. See help weboptions for a complete list of supported HTTP options.

See also: weboptions, webread.

: output = weboptions ()
: output = weboptions (name1, value1, …)

Specify parameters for RESTful web services.

weboptions with no inputs returns a default weboptions object to specify parameters for a request to a web service. A weboptions object can be an optional input argument to the webread and webwrite functions.

Multiple name and value pair arguments may be specified in any order as name1, value1, name2, value2, etc.

The option names must match exactly one of those specified in the table below.

The following options are available:

See also: webread, webwrite.


Next: , Previous: , Up: Networking Utilities   [Contents][Index]