Class

# URLConnection

<div class="rst-class">

forsearch

</div>

REST

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Used to send and receive data using the HTTP 1.1+ protocol.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                                                   | Type                               | Read-Only | Shared |
|------------------------------------------------------------------------|------------------------------------|-----------|--------|
| `AllowCertificateValidation<urlconnection.allowcertificatevalidation>` | `Boolean</api/data_types/boolean>` |           |        |
| `FollowRedirects<urlconnection.followredirects>`                       | `Boolean</api/data_types/boolean>` |           |        |
| `HTTPStatusCode<urlconnection.httpstatuscode>`                         | `Integer</api/data_types/integer>` | ✓         |        |
| `Password<urlconnection.password>`                                     | `String</api/data_types/string>`   |           |        |
| `UserName<urlconnection.username>`                                     | `String</api/data_types/string>`   |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                     | Parameters                                                                                                                                                                           | Returns                            | Shared |
|----------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|--------|
| `ClearRequestHeaders<urlconnection.clearrequestheaders>` |                                                                                                                                                                                      |                                    |        |
| `Disconnect<urlconnection.disconnect>`                   |                                                                                                                                                                                      |                                    |        |
| `RequestHeader<urlconnection.requestheader>`             | name As `String</api/data_types/string>`                                                                                                                                             | `String</api/data_types/string>`   |        |
|                                                          | name As `String</api/data_types/string>`, `Assigns</api/language/assigns>` value As `String</api/data_types/string>`                                                                 |                                    |        |
| `ResponseHeader<urlconnection.responseheader>`           | name As `String</api/data_types/string>`                                                                                                                                             | `String</api/data_types/string>`   |        |
| `ResponseHeaders<urlconnection.responseheaders>`         |                                                                                                                                                                                      | `Iterator</api/language/iterator>` |        |
| `Send<urlconnection.send>`                               | method As `String</api/data_types/string>`, URL As `String</api/data_types/string>`, file As `FolderItem</api/files/folderitem>`, timeout As `Integer</api/data_types/integer>` = 60 |                                    |        |
|                                                          | method As `String</api/data_types/string>`, URL As `String</api/data_types/string>`, timeout As `Integer</api/data_types/integer>` = 60                                              |                                    |        |
| `SendSync<urlconnection.sendsync>`                       | method As `String</api/data_types/string>`, URL As `String</api/data_types/string>`, file As `FolderItem</api/files/folderitem>`, timeout As `Integer</api/data_types/integer>` = 0  |                                    |        |
|                                                          | method As `String</api/data_types/string>`, URL As `String</api/data_types/string>`, timeout As `Integer</api/data_types/integer>` = 0                                               | `String</api/data_types/string>`   |        |
| `SetRequestContent<urlconnection.setrequestcontent>`     | content As `String</api/data_types/string>`, mimeType As `String</api/data_types/string>`                                                                                            |                                    |        |

## Events

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                             | Parameters                                                                                                                                                                                  | Returns                            |
|------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|
| `AuthenticationRequested<urlconnection.authenticationrequested>` | realm As `String</api/data_types/string>`, `ByRef</api/language/byref>` name As `String</api/data_types/string>`, `ByRef</api/language/byref>` password As `String</api/data_types/string>` | `Boolean</api/data_types/boolean>` |
| `ContentReceived<urlconnection.contentreceived>`                 | URL As `String</api/data_types/string>`, HTTPStatus As `Integer</api/data_types/integer>`, content As `String</api/data_types/string>`                                                      |                                    |
| `Error<urlconnection.error>`                                     | err As `RuntimeException</api/exceptions/runtimeexception>`                                                                                                                                 |                                    |
| `FileReceived<urlconnection.filereceived>`                       | URL As `String</api/data_types/string>`, HTTPStatus As `Integer</api/data_types/integer>`, file As `FolderItem</api/files/folderitem>`                                                      |                                    |
| `HeadersReceived<urlconnection.headersreceived>`                 | URL As `String</api/data_types/string>`, HTTPStatus As `Integer</api/data_types/integer>`                                                                                                   |                                    |
| `ReceivingProgressed<urlconnection.receivingprogressed>`         | bytesReceived As `Int64</api/data_types/additional_types/int64>`, totalBytes As `Int64</api/data_types/additional_types/int64>`, newData As `String</api/data_types/string>`                |                                    |
| `SendingProgressed<urlconnection.sendingprogressed>`             | bytesSent As `Int64</api/data_types/additional_types/int64>`, bytesLeft As `Int64</api/data_types/additional_types/int64>`                                                                  |                                    |

## Property descriptions

<div id="urlconnection.allowcertificatevalidation">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.AllowCertificateValidation

**AllowCertificateValidation** As `Boolean</api/data_types/boolean>`

> When set to `True</api/language/true>`, the connection requires that the server's certificate is valid. The Error event is called if the certificate is not valid. The default value is `True</api/language/true>`.

<div id="urlconnection.followredirects">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.FollowRedirects

**FollowRedirects** As `Boolean</api/data_types/boolean>`

> When set to `True</api/language/true>`, the request will follow redirects. When `False</api/language/false>` it will not. The default value is `True</api/language/true>`.

<div id="urlconnection.httpstatuscode">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.HTTPStatusCode

**HTTPStatusCode** As `Integer</api/data_types/integer>`

> The HTTP status code when using the SendSync methods.
>
> This property is read-only.
>
> This code reads the HTTP status code after a synchronous request:
>
> ``` xojo
> Var content As String
> content = MyConnection.SendSync("GET", "http://127.0.0.1:8080/GetData", 30)
> Var status As Integer = MyConnection.HTTPStatusCode
> ```

<div id="urlconnection.password">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.Password

**Password** As `String</api/data_types/string>`

> The password to be used to authentication.
>
> Unlike other supported operating systems where user authentication is done via the `AuthenticationRequested<urlconnection.authenticationrequested>` event, on Android, the `UserName<urlconnection.username>` and *Password* must be provided (via properties) before sending the request.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> This property is only supported for Android.
>
> </div>

<div id="urlconnection.username">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.UserName

**UserName** As `String</api/data_types/string>`

> The username to be used to authentication.
>
> Unlike other supported operating systems where user authentication is done via the `AuthenticationRequested<urlconnection.authenticationrequested>` event, on Android, the *UserName* and `Password<urlconnection.password>` must be provided (via properties) before sending the request.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> This property is only supported for Android.
>
> </div>

## Method descriptions

<div id="urlconnection.clearrequestheaders">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.ClearRequestHeaders

**ClearRequestHeaders**

> Clears all of the request headers, which is useful if you are using the socket to send a different request.
>
> ``` xojo
> mySocket.ClearRequestHeaders
> ```

<div id="urlconnection.disconnect">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.Disconnect

**Disconnect**

> Disconnects the socket.
>
> A disconnected socket is not set to Nil and may be reused.

<div id="urlconnection.requestheader">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.RequestHeader

**RequestHeader**(name As `String</api/data_types/string>`) As `String</api/data_types/string>`

> Gets the request header with the key of name. The Name parameter's encoding is converted to ASCII. If the header does not exist in the request headers, an empty String is returned. Raises a RuntimeException if the encoding could not be converted to ASCII.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="rst-class">

forsearch

</div>

URLConnection.RequestHeader

**RequestHeader**(name As `String</api/data_types/string>`, `Assigns</api/language/assigns>` value As `String</api/data_types/string>`)

> Sets the request header with the key of name. The Name parameter's encoding is converted to ASCII.
>
> The parameter `name` is the name of the key to get or set and `value` ist the value for the key.
>
> Sets an API key as a token in the request header:
>
> ``` xojo
> Self.RequestHeader("Authorization") = "MyAPIKey"
> mySocket.Send("GET", "http://www.webservice.com/GetData")
> ```

<div id="urlconnection.responseheader">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.ResponseHeader

**ResponseHeader**(name As `String</api/data_types/string>`) As `String</api/data_types/string>`

> Gets a response header.

<div id="urlconnection.responseheaders">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.ResponseHeaders

**ResponseHeaders** As `Iterator</api/language/iterator>`

> Used to iterate over all response headers.
>
> ``` xojo
> Var connection As New URLConnection
> Var headers() As Pair
>
> For Each header As Pair In connection.ResponseHeaders
>     headers.AddRow(header.Left : header.Right)
> Next
> ```

<div id="urlconnection.send">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.Send

**Send**(method As `String</api/data_types/string>`, URL As `String</api/data_types/string>`, file As `FolderItem</api/files/folderitem>`, timeout As `Integer</api/data_types/integer>` = 60)

> Asynchronously sends a request using an HTTP method such as GET or POST. Send can be used to send both standard "http" and secure "https" requests. The *timeout* is in seconds.
>
> If you pass "GET" as the *method*, the `FileReceived<urlconnection.filereceived>` event will be called with the file received from the server passed to it.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="rst-class">

forsearch

</div>

URLConnection.Send

**Send**(method As `String</api/data_types/string>`, URL As `String</api/data_types/string>`, timeout As `Integer</api/data_types/integer>` = 60)

> Asynchronously sends a request using an HTTP method such as GET or POST. Send can be used to send both standard "http" and secure "https" requests. The *timeout* is in seconds.
>
> If you pass "GET" as the *method*, or use the Send *method* to communicate with the server, the `ContentReceived<urlconnection.contentreceived>` event will be called with the content received from the server passed to it.
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> The timeout is in seconds and currently can be a maximum of 60 seconds (75 on macOS). A connection that times out will raise the Error event. You can view the timeout length on macOS with this Terminal command: `sysctl net.inet.tcp.keepinit`. You can change it using this command (specify the value in milliseconds): `sysctl net.inet.tcp.keepinit=30000`.
>
> </div>
>
> This example sends a request. The ContentReceived event is called with the response:
>
> ``` xojo
> MyConnection.Send("GET", "http://127.0.0.1:8080/GetData")
> ```
>
> Sends a GET request, saving (downloading) the response to a file sent to the FileReceived event:
>
> ``` xojo
> Var outputFile As FolderItem = SpecialFolder.Documents.Child("data.json")
> MyConnection.Send("GET", "http://127.0.0.1:8080/GetData", outputFile)
> ```
>
> To make a secure request, use "https" in the URL:
>
> ``` xojo
> Var outputFile As FolderItem = SpecialFolder.Documents.Child("data.json")
> MyConnection.Send("GET", "https://www.mydomain.com/GetData", outputFile)
> ```

<div id="urlconnection.sendsync">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.SendSync

**SendSync**(method As `String</api/data_types/string>`, URL As `String</api/data_types/string>`, file As `FolderItem</api/files/folderitem>`, timeout As `Integer</api/data_types/integer>` = 0)

> Synchronously sends a request using an HTTP method such as GET or POST and returns the output in file. The results are saved to the supplied *file*. Send can be used to send both standard http and secure https requests. The *timeout* is in seconds.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="rst-class">

forsearch

</div>

URLConnection.SendSync

**SendSync**(method As `String</api/data_types/string>`, URL As `String</api/data_types/string>`, timeout As `Integer</api/data_types/integer>` = 0) As `String</api/data_types/string>`

> Synchronously sends a request using an HTTP method such as GET or POST. Results are returned as a String. Send can be used to send both standard http and secure https requests. The *timeout* is in seconds.
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> Be aware that calling SendSync can cause your app's UI to "freeze" while it waits for the result. For normal processing you may want to use the asynchronous Send method instead, which calls the ContentReceived or FileReceived events when data is received.
>
> </div>
>
> This method raises a `RuntimeException</api/exceptions/runtimeexception>` if an App Transport Security error occurs on macOS due to using a non-secure URL without the appropriate entry in the plist.
>
> ``` xojo
> Var content As String
> content = MyConnection.SendSync("GET", "http://127.0.0.1:8080/GetData", 30)
> ```
>
> Sends a GET request, saving the response to a file:
>
> ``` xojo
> Var outputFile As FolderItem = SpecialFolder.Documents.Child("data.json")
> MyConnection.SendSync("GET", "http://127.0.0.1:8080/GetData", outputFile, 30)
> ```
>
> To make a secure request, use "https" in the URL:
>
> ``` xojo
> Var outputFile As FolderItem = SpecialFolder.Documents.Child("data.json")
> MyConnection.SendSync("GET", "https://www.mydomain.com/GetData", outputFile, 30)
> ```

<div id="urlconnection.setrequestcontent">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.SetRequestContent

**SetRequestContent**(content As `String</api/data_types/string>`, mimeType As `String</api/data_types/string>`)

> Sets the *content* data and content *type* to be sent to the server.
>
> Sends a POST request with \`JSON\`:
>
> ``` xojo
> Var json As New JSONItem
> json.Value("ID") = 123456
>
> mySocket.SetRequestContent(json.ToString, "application/json")
> mySocket.Send("POST", "http://127.0.0.1:8080/GetCustomer")
> ```
>
> To send form information, you build the String yourself:
>
> ``` xojo
> ' Build form String
> Var formText As String = "firstName=Bob&lastName=Roberts"
>
> ' POST it
> mySocket.SetRequestContent(formText, "application/x-www-form-urlencoded")
> mySocket.Send("POST", "http://www.webserviceurl.com")
> ```

## Event descriptions

<div id="urlconnection.authenticationrequested">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.AuthenticationRequested

**AuthenticationRequested**(realm As `String</api/data_types/string>`, `ByRef</api/language/byref>` name As `String</api/data_types/string>`, `ByRef</api/language/byref>` password As `String</api/data_types/string>`) As `Boolean</api/data_types/boolean>`

> Called when the connection requires HTTP basic authentication. Set the name and password and return `True</api/language/true>`.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> This event is not supported for Android. The `UserName<urlconnection.username>` and `Password<urlconnection.password>` properties must be populated before the connection is made.
>
> </div>
>
> Specify a name and password:
>
> ``` xojo
> name = "MyUserName"
> password = "MyPassword"
> Return True
> ```

<div id="urlconnection.contentreceived">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.ContentReceived

**ContentReceived**(URL As `String</api/data_types/string>`, HTTPStatus As `Integer</api/data_types/integer>`, content As `String</api/data_types/string>`)

> Called when a new page has been retrieved from the server as a result of calling Send.
>
> The encoding of *content* is set to the content-type encoding (charset) of the incoming content.

<div id="urlconnection.error">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.Error

**Error**(err As `RuntimeException</api/exceptions/runtimeexception>`)

> Called when an HTTP error occurs.
>
> The ErrorNumber values in the err exception vary by platform. Here are links to errors by platform:
>
> - [Windows HTTP Errors](https://msdn.microsoft.com/en-us/library/windows/desktop/aa383770(v=vs.85).aspx)
> - [macOS NSURLError.h](https://github.com/apportable/Foundation/blob/master/System/Foundation/include/Foundation/NSURLError.h)
> - [Linux libsoup status codes](https://libsoup.gnome.org/libsoup-3.0/enum.Status.html)
>
> Display information about the error:
>
> ``` xojo
> ErrorLabel.Text = e.Reason
> ```

<div id="urlconnection.filereceived">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.FileReceived

**FileReceived**(URL As `String</api/data_types/string>`, HTTPStatus As `Integer</api/data_types/integer>`, file As `FolderItem</api/files/folderitem>`)

> n a download of a file is completed as a result of calling Send and passing a FolderItem.

<div id="urlconnection.headersreceived">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.HeadersReceived

**HeadersReceived**(URL As `String</api/data_types/string>`, HTTPStatus As `Integer</api/data_types/integer>`)

> Called when headers are received from the server.

<div id="urlconnection.receivingprogressed">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.ReceivingProgressed

**ReceivingProgressed**(bytesReceived As `Int64</api/data_types/additional_types/int64>`, totalBytes As `Int64</api/data_types/additional_types/int64>`, newData As `String</api/data_types/string>`)

> Call periodically as data is received.

<div id="urlconnection.sendingprogressed">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

URLConnection.SendingProgressed

**SendingProgressed**(bytesSent As `Int64</api/data_types/additional_types/int64>`, bytesLeft As `Int64</api/data_types/additional_types/int64>`)

> Called periodically as data is sent/uploaded.

## Notes

Usage on Linux requires libsoup3 with a fallback to libsoup2-4.

<span class="title-ref">URLConnection</span> handles both standard "http" connections and secure "https" connections.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Standard Method Definitions

`GET` and `POST` are most commonly used, but there are other methods as well. For example, to get just the headers you can use the HEAD method. The full list of methods is available on the [W3 HTTP/1.1 Method Definition](https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html) page.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Cookies

When using <span class="title-ref">URLConnection</span> on macOS, cookies are shared globally across all sessions. On Windows and Linux they are exclusive to the <span class="title-ref">URLConnection</span> session. Once the connection ends, the cookies are gone.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### macOS information (app transport security)

Starting with OS X 10.11, you have to use secure "https" connections or you will get this error: "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection". To continue to connect to non-secure "http" connections that you do not control you'll have to provide a plist with a temporary exception specified for each site you are accessing via http:

``` xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>firstsite.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
            <key>secondsite.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
    </dict>
</dict>
</plist>
```

If you don't know the specific sites, you can request access to everything using a single key:

``` xojo
<key>NSAppTransportSecurity</key>
<dict>
  <!-- Include to allow all connections; avoid if possible -->
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>
```

Apple may reject an App Store submission if the app uses these settings without valid reasons.

For more information about this, refer to [NSAppTransportSecurity](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW33) in Apple's docs.

For more information: `Using Non-Secure URLs on macOS and iOS</topics/communication/internet/using_non-secure_urls_on_macos_and_ios>`, `Using a plist</topics/application_structure/ios/using_a_plist>`

To test a site to see what plist exceptions it might need you can use this Terminal command:

`/usr/bin/nscurl --ats-diagnostics --verbose https://example.com`

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`Object</api/data_types/additional_types/object>` parent class; `Using Non-Secure URLs on macOS and iOS</topics/communication/internet/using_non-secure_urls_on_macos_and_ios>`, `Using a plist</topics/application_structure/ios/using_a_plist>` topics; [Paw Extension](https://github.com/xojo/Paw-XojoURLConnectionGenerator) on GitHub

</div>
