URLFetch

URLFetch["url"]
returns the contents of a URL as a string.

URLFetch["url",elements]
returns the specified elements from a URL.

Details and OptionsDetails 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
    "All"return 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"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
    "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.

ExamplesExamplesopen allclose all

Basic Examples  (3)Basic Examples  (3)

This returns the content of the URL:

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

Passing data to the server:

In[1]:=
Click for copyable input

Gather information about a connection:

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