---
title: "URLSave"
language: "en"
type: "Symbol"
summary: "URLSave is being phased out in favor of URLDownload, which was introduced experimentally in Version 11."
keywords: 
- wget
- web scrape
- web crawl
- cache
- save web page
- cache web page
- save web site
- save website
- cache website
canonical_url: "https://reference.wolfram.com/language/ref/URLSave.html"
source: "Wolfram Language Documentation"
related_functions: 
  - 
    title: "URLRead"
    link: "https://reference.wolfram.com/language/ref/URLRead.en.md"
  - 
    title: "CopyFile"
    link: "https://reference.wolfram.com/language/ref/CopyFile.en.md"
---
# URLSave

⚠ ``URLSave`` is being phased out in favor of ``URLDownload``, which was introduced experimentally in Version 11.

URLSave["url"] saves the content of the URL to a file in \$TemporaryDirectory.

URLSave["url", "file"] saves the content of the URL to a file.

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

## Details and Options

* Types of elements supported:

|              |                                             |
| ------------ | ------------------------------------------- |
| "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:

|                              |                                                 |
| ---------------------------- | ----------------------------------------------- |
| "elem"                       | return 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"           | Automatic | cookies to pass to the server                                     |
| "StoreCookies"      | True      | whether to store received cookies                                 |
| "VerifyPeer"        | True      | verify authenticity using SSL certificates                        |
| "UserAgent"         | Automatic | user agent string to send                                         |
| "ReadTimeout"       | 0         | time to allow for uploading or downloading data                   |
| "ConnectTimeout"    | 0         | time to allow for connecting to the server                        |
| BinaryFormat        | True      | whether to avoid textual interpretation of newlines or other data |
| "FollowRedirects"   | True      | whether to follow redirects                                       |

---

## Examples (18)

### Basic Examples (3)

This saves the content of the URL:

```wl
In[1]:= URLSave["www.wolfram.com", FileNameJoin[{$TemporaryDirectory, "index.html"}]]

Out[1]= "/tmp/index.html"
```

---

Download a file and check the status code returned from the server:

```wl
In[1]:= URLSave["wolframalpha.com", FileNameJoin[{$TemporaryDirectory, "alpha.html"}], "StatusCode"]

Out[1]= 200
```

---

Gather information about a connection:

```wl
In[1]:= URLSave["www.wolfram.com", FileNameJoin[{$TemporaryDirectory, "index.html"}], "All"]

Out[1]= {{{"Date", "Wed, 15 Feb 2012 19:49:56 GMT"}, {"Server", "Apache"}, {"Set-Cookie", "WR_SID=8cb1c8ef3934f3c0c64841e; path=/; expires=Sat, 12-Feb-22 19:49:56 GMT; domain=.wolfram.com"}, {"Content-Language", "en"}, {"Vary", "Accept-Language"}, {"Conten ... :47:06", "Name" -> "WR_SID", "Value" -> "140.177.200.239.1329335225983876"}, {"Domain" -> ".wolfram.com", "Path" -> "/", "Secure" -> "FALSE", "Expires" -> "Sat 12 Feb 2022 19:49:56", "Name" -> "WR_SID", "Value" -> "8cb1c8ef3934f3c0c64841e"}}, 200}
```

### Options (13)

#### "Method" (1)

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

```wl
In[1]:= tmpFile  = FileNameJoin[{$TemporaryDirectory, "tmp.txt"}];

In[2]:= URLSave["http://wolfram.com", tmpFile, "Headers", "Method" -> "HEAD"]

Out[2]= {{"Date", "Mon, 01 Oct 2012 18:01:17 GMT"}, {"Server", "Apache"}, {"Set-Cookie", "WR_SID=8cb1c8fe28285069da6dd911; path=/; expires=Thu, 29-Sep-22 18:01:17 GMT; domain=.wolfram.com"}, {"Content-Language", "en"}, {"Vary", "Accept-Language"}, {"Content-Location", "/index.en.html"}, {"Content-Type", "text/html"}}
```

#### "Parameters" (1)

Specify the parameters that should be sent to the server:

```wl
In[1]:= tmpFile  = FileNameJoin[{$TemporaryDirectory, "tmp.txt"}];

In[2]:= URLSave["http://exampledata.wolfram.com/httpget.php", tmpFile, "Parameters" -> {"name" -> "Joe", "age" -> "30"}];

In[3]:= FilePrint[tmpFile]

Joe is 30 years old.

```

#### "VerifyPeer" (1)

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

```wl
In[1]:= tmpFile  = FileNameJoin[{$TemporaryDirectory, "tmp.txt"}];

In[2]:= URLSave["https://wolfram.com", tmpFile, "StatusCode", "VerifyPeer" -> True]

Out[2]= 200
```

#### "Username" (1)

Specify the username that should be sent to the server:

```wl
In[1]:= tmpFile  = FileNameJoin[{$TemporaryDirectory, "tmp.txt"}];

In[2]:= URLSave["http://exampledata.wolfram.com/authentication.php", tmpFile, "Username" -> "Joe", "Password" -> ""];

In[3]:= FilePrint[tmpFile]

Hello Joe.You entered  as your password.
```

#### "Password" (1)

Specify the password that should be sent to the server:

```wl
In[1]:= tmpFile  = FileNameJoin[{$TemporaryDirectory, "tmp.txt"}];

In[2]:= URLSave["http://exampledata.wolfram.com/authentication.php", tmpFile, "Username" -> "Joe", "Password" -> "topsecret"];

In[3]:= FilePrint[tmpFile]

Hello Joe.You entered topsecret as your password.
```

#### "UserAgent" (1)

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

```wl
In[1]:= tmpFile  = FileNameJoin[{$TemporaryDirectory, "tmp.txt"}];

In[2]:= URLSave["http://exampledata.wolfram.com/useragent.php", tmpFile, "UserAgent" -> "Web Browser"];

In[3]:= FilePrint[tmpFile]

Web Browser
```

#### "Cookies" (1)

Manually control the cookies used by ``URLSave`` :

```wl
In[1]:= tmpFile  = FileNameJoin[{$TemporaryDirectory, "tmp.txt"}];

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

In[3]:= FilePrint[tmpFile]

MyCookie--> CookieData
 
```

#### "StoreCookies" (1)

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

```wl
In[1]:= tmpFile  = FileNameJoin[{$TemporaryDirectory, "tmp.txt"}];

In[2]:= URLSave["http://wolfram.com/", tmpFile, "Cookies", "StoreCookies" -> False]

Out[2]= {{"Domain" -> ".wolfram.com", "Path" -> "/", "Secure" -> "FALSE", "Expires" -> "Thu 29 Sep 2022 18:05:53", "Name" -> "WR_SID", "Value" -> "8cb1c8fe5e805069db8147d"}}

In[3]:= $HTTPCookies

Out[3]= {}
```

#### "Headers" (1)

Specify headers to be sent to the server:

```wl
In[1]:= tmpFile  = FileNameJoin[{$TemporaryDirectory, "tmp.txt"}];

In[2]:= URLSave["http://exampledata.wolfram.com/headers.php", tmpFile, "Headers" -> {"MyHeader" -> "42"}];

In[3]:= FilePrint[tmpFile]

Accept: */*
Host: exampledata.wolfram.com
MyHeader: 42
User-Agent: Mathematica HTTPClient 9.

```

#### "BodyData" (1)

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

```wl
In[1]:= tmpFile  = FileNameJoin[{$TemporaryDirectory, "tmp.txt"}];

In[2]:= URLSave["http://exampledata.wolfram.com/bodydata.php", tmpFile, "BodyData" -> "Message body data sent to server."];

In[3]:= FilePrint[tmpFile]

Message body data sent to server.
```

#### "MultipartData" (1)

Specify the contents of a multipart message body:

```wl
In[1]:= tmpFile  = FileNameJoin[{$TemporaryDirectory, "tmp.txt"}];

In[2]:= URLSave["http://exampledata.wolfram.com/multipartdata.php", tmpFile, "MultipartData" -> {{"partName", "mime/type", {1, 2, 3, 4, 5}}}];

In[3]:= FilePrint[tmpFile]

7cfdd07889b3295d6a550914ab35e068
```

#### "ReadTimeout" (1)

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

```wl
In[1]:= tmpFile  = FileNameJoin[{$TemporaryDirectory, "tmp.txt"}];

In[2]:= URLSave["http://exampledata.wolfram.com/50mb.dat", tmpFile, "ReadTimeout" -> 1]
```

URLSave::invhttp: Timeout was reached.

```wl
Out[2]= $Failed
```

#### "ConnectTimeout" (1)

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

```wl
In[1]:= tmpFile  = FileNameJoin[{$TemporaryDirectory, "tmp.txt"}];

In[2]:= URLSave["http://127.0.0.1", tmpFile, "ConnectTimeout" -> 1]
```

URLSave::invhttp: Timeout was reached.

```wl
Out[2]= $Failed
```

### Properties & Relations (2)

Use ``URLFetch`` to load the content directly into the Wolfram Language:

```wl
In[1]:= Short[URLFetch["http://exampledata.wolfram.com/USConstitution.txt"]]

Out[1]//Short=
"
We the People of the United"…"tives shall
have intervened.
"
```

---

Use ``Get`` for loading Wolfram Language expressions directly over HTTP:

```wl
In[1]:= Get["http://exampledata.wolfram.com/Collatz.m"]

In[2]:= Collatz[5]

Out[2]= {5, 16, 8, 4, 2, 1}
```

## See Also

* [`URLRead`](https://reference.wolfram.com/language/ref/URLRead.en.md)
* [`CopyFile`](https://reference.wolfram.com/language/ref/CopyFile.en.md)

## History

* [Introduced in 2012 (9.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn90.en.md)