({{, URLFetch[url]
returns the contents of a URL as a string.}, {, URLFetch[url,elements]
returns the specified elements from a URL.}})

OpenersNotesSection(Spacer1)Details and Options

Types of elements supported:

The following forms of element specifications can be given:

The following options can be given:

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.

OpenersPrimaryExamplesSection(Spacer1)Examples  (18)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

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

StringTake[URLFetch["www.wolfram.com"],200]

Passing data to the server:

URLFetch["search.wolfram.com", "Parameters"->{"query"->"Wolfram HTTPClient"}];

Gather information about a connection:

URLFetch[URL["www.wolfram.com"], {"Headers","Cookies", "StatusCode"}]

OpenersExampleSection1(Spacer1)Options  (13)

OpenersExampleSubsection0(Spacer1)Method  (1)

(RefLink[Method, paclet:ref/Method]) can be used to specify the HTTP method used by the connection:

URLFetch["http://wolfram.com", "Headers",Method->"HEAD"]

OpenersExampleSubsection1(Spacer1)"Parameters"  (1)

Specify the parameters that should be sent to the server:

URLFetch[URL["http://exampledata.wolfram.com/httpget.php"], "Parameters"->{"name"->"Joe", "age"->"30"}]

OpenersExampleSubsection2(Spacer1)"VerifyPeer"  (1)

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

URLFetch["https://wolfram.com", "StatusCode","VerifyPeer"->True]

OpenersExampleSubsection3(Spacer1)"Username"  (1)

Specify the username that should be sent to the server:

URLFetch[URL["http://exampledata.wolfram.com/authentication.php"], "Username"->"Joe", "Password"->""]

OpenersExampleSubsection4(Spacer1)"Password"  (1)

Specify the password that should be sent to the server:

URLFetch["http://exampledata.wolfram.com/authentication.php","Username"->"Joe","Password"->"topsecret"]

OpenersExampleSubsection5(Spacer1)"UserAgent"  (1)

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

URLFetch[URL["http://exampledata.wolfram.com/useragent.php"], "UserAgent"->"Web Browser"]

OpenersExampleSubsection6(Spacer1)"Cookies"  (1)

Manually control the cookies used by URLFetch:

URLFetch["http://exampledata.wolfram.com/cookies.php", "Cookies"->{{"Domain"->".exampledata.wolfram.com", "Path"->"/", "Secure"->"FALSE", "Expires"->DateString[{2020, 1, 1, 0, 0, 0}], "Name"->"MyCookie", "Value"->"CookieData"}}]

OpenersExampleSubsection7(Spacer1)"StoreCookies"  (1)

If (RefLink[False, paclet:ref/False]), "StoreCookies" will not place any new cookies found while connecting to the site in the global cookie share:

URLFetch[URL["http://wolfram.com/"], "Cookies", "StoreCookies"->False]

$HTTPCookies

OpenersExampleSubsection8(Spacer1)"Headers"  (1)

Specify headers to be sent to the server:

URLFetch["http://exampledata.wolfram.com/headers.php", "Headers"->{"MyHeader"->"42"}]

OpenersExampleSubsection9(Spacer1)"Body"  (1)

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

URLFetch[URL["http://exampledata.wolfram.com/bodydata.php"], "Body"->"Message body data sent to server."]

OpenersExampleSubsection10(Spacer1)"MultipartElements"  (1)

Specify the contents of a multipart message body:

URLFetch["http://exampledata.wolfram.com/multipartdata.php",Method->"POST","MultipartElements"->{{"partName", "mime/type"}-> {1,2,3,4,5}}]

OpenersExampleSubsection11(Spacer1)"ReadTimeout"  (1)

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

URLFetch["http://exampledata.wolfram.com/50mb.dat", "ReadTimeout"->1]

OpenersExampleSubsection12(Spacer1)"ConnectTimeout"  (1)

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

URLFetch[IPAddress["127.0.0.1"], "ConnectTimeout"->1]

OpenersExampleSection2(Spacer1)Properties & Relations  (2)

Use (RefLink[URLSave, paclet:ref/URLSave]) to store output in a file:

URLSave["http://wolfram.com",FileNameJoin[{$TemporaryDirectory,"index.html"}]]

Use (RefLink[Get, paclet:ref/Get]) for loading Wolfram Language expressions directly over HTTP:

Get["http://exampledata.wolfram.com/Collatz.m"]

Collatz[5]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[URLExecute, paclet:ref/URLExecute])  ▪  (RefLink[SystemOpen, paclet:ref/SystemOpen])  ▪  (RefLink[CloudGet, paclet:ref/CloudGet])  ▪  (RefLink[CloudImport, paclet:ref/CloudImport])  ▪  (RefLink[HTTPRequestData, paclet:ref/HTTPRequestData])}})}})