URLFetchAsynchronous

URLFetchAsynchronous["url",eventFunction]
performs a connection in the background, calling the eventFunction when an event is raised.

Details and OptionsDetails and Options

  • Types of events that may be raised:
  • "data"returns a list of bytes and indicates that the connection has completed
    "progress"returns information about the current connect of the form
    "error"indicates that an error occurred while attempting to connect to a URL
    "headers"headers received from the web server
    "cookies"a list of all known cookies
    "statuscode"the status code returned by the server
  • 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"Truecookies to pass to the server
    "StoreCookies"Automaticwhether 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
    "Progress"Falsewhether to raise a event
    "Transfer"Automaticif Automatic, the event returns once and returns all the data downloaded; if , the event is raised multiple times with the data downloaded since the last event was raised
    "UserData"Noneany expression passed to this option will be stored for use of the AsynchronousTaskObject inside the event function; the data can be found by checking the options of AsynchronousTaskObject passed to the event function
    "FollowRedirects"Truewhether to follow redirects
  • Allowed times are by default given in seconds.
  • Multipart elements must be of the form , where val is a string or a list of bytes.
  • When an event is raised, the event function passed to URLFetchAsynchronous will be executed. The event functions will be passed three arguments, the AsynchronousTaskObject, the event name, and the data received from the event. Event functions are the only method for handling data received from URLFetchAsynchronous.

ExamplesExamplesopen allclose all

Basic Examples  (3)Basic Examples  (3)

This opens a dialog when the download has finished:

In[1]:=
Click for copyable input
Out[1]=

Store headers and cookies:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
Out[2]=

Use the status code and error event to determine the availability of URLs.

In[1]:=
Click for copyable input
Out[1]=
Out[1]=
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
Introduced in 2012
(9.0)