URLFetch

URLFetch is being phased out in favor of URLRead and URLExecute, which were introduced experimentally in Version 11.

URLFetch[url]

returns the contents of a URL as a string.

URLFetch[url,elements]

returns the specified elements from a URL.

Details and Options

  • Types of elements supported:
  • "Content"a string of the URL's content
    "ContentData"a list of bytes of the URL's content
    "Headers"a list of all headers received from the URL
    "Cookies"a list of all known cookies
    "StatusCode"the status code returned by the server
  • The following forms of element specifications can be given:
  • elemreturn a single element
    {elem1,elem2,}return several elements
    {"Rules",{elem1,elem2,}}return several elements as a list of rules
    "Rules"return all possible elements as a list of rules
    Allreturn all possible elements as a list
  • The following options can be given:
  • Method"GET"method to use for request
    "Parameters"{}parameters to be sent for the request
    "Body"""contents of message body to be sent
    "MultipartElements"{}list of multipart data elements to send
    "Username"""username to use for the request
    "Password"""password to use for the request
    "Headers"{}headers to be manually sent to the HTTP server
    "Cookies"Automaticcookies to pass to the server
    "StoreCookies"Truewhether to store received cookies
    "VerifyPeer"Trueverify authenticity using SSL certificates
    "UserAgent"Automaticuser agent string to send
    "ReadTimeout"0time to allow for uploading or downloading data
    "ConnectTimeout"0time to allow for connecting to the server
    "FollowRedirects"Truewhether to follow redirects
  • Allowed times are by default given in seconds.
  • Multipart elements must be of the form {"name","mimetype"}->val, where val is a string or a list of bytes.

Examples

open allclose all

Basic Examples  (3)

Fetch data from a URL, taking the first 200 characters of the result:

Passing data to the server:

Gather information about a connection:

Options  (13)

Method  (1)

Method can be used to specify the HTTP method used by the connection:

"Parameters"  (1)

Specify the parameters that should be sent to the server:

"VerifyPeer"  (1)

Verify that the SSL certificate used by the server is valid:

"Username"  (1)

Specify the username that should be sent to the server:

"Password"  (1)

Specify the password that should be sent to the server:

"UserAgent"  (1)

Specify the user agent that should be sent to the server:

"Cookies"  (1)

Manually control the cookies used by URLFetch:

"StoreCookies"  (1)

If False, "StoreCookies" will not place any new cookies found while connecting to the site in the global cookie share:

"Headers"  (1)

Specify headers to be sent to the server:

"Body"  (1)

Specify the message body that should be sent when connecting to the server:

"MultipartElements"  (1)

Specify the contents of a multipart message body:

"ReadTimeout"  (1)

Specify the maximum allotted time in seconds to finish downloading data from the server:

"ConnectTimeout"  (1)

Specify the maximum allotted time in seconds to establish a connection to the server:

Properties & Relations  (2)

Use URLSave to store output in a file:

Use Get for loading Wolfram Language expressions directly over HTTP:

Introduced in 2012
 (9.0)