<div class="meta" robots="noindex">

</div>

Class

# Xojo.Net.HTTPSocket

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

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2020r2. Please use `URLConnection</api/networking/urlconnection>` as a replacement.

</div>

## Description

Used to send and receive data via the HTTP 1.1 protocol.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                                             | Type                               | Read-Only | Shared |
|------------------------------------------------------------------|------------------------------------|-----------|--------|
| `ValidateCertificates<xojo.net.httpsocket.validatecertificates>` | `Boolean</api/data_types/boolean>` |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                           | Parameters                                                                                     | Returns                          | Shared |
|----------------------------------------------------------------|------------------------------------------------------------------------------------------------|----------------------------------|--------|
| `ClearRequestHeaders<xojo.net.httpsocket.clearrequestheaders>` |                                                                                                |                                  |        |
| `Disconnect<xojo.net.httpsocket.disconnect>`                   |                                                                                                |                                  |        |
| `ResponseHeader<xojo.net.httpsocket.responseheader>`           | name As `String</api/data_types/string>`                                                       | `String</api/data_types/string>` |        |
| `SetRequestContent<xojo.net.httpsocket.setrequestcontent>`     | data As `MemoryBlock</api/language/memoryblock>`, mimeType As `String</api/data_types/string>` |                                  |        |

## Events

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                                 | Parameters                                                                                                                                                                                  | Returns |
|----------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|
| `AuthenticationRequired<xojo.net.httpsocket.authenticationrequired>` | 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>` |         |
| `Error<xojo.net.httpsocket.error>`                                   | err As `RuntimeException</api/exceptions/runtimeexception>`                                                                                                                                 |         |
| `FileReceived<xojo.net.httpsocket.filereceived>`                     | URL As `String</api/data_types/string>`, HTTPStatus As `Integer</api/data_types/integer>`, file As `FolderItem</api/files/folderitem>`                                                      |         |
| `HeadersReceived<xojo.net.httpsocket.headersreceived>`               | URL As `String</api/data_types/string>`, HTTPStatus As `Integer</api/data_types/integer>`                                                                                                   |         |
| `PageReceived<xojo.net.httpsocket.pagereceived>`                     | URL As `String</api/data_types/string>`, HTTPStatus As `Integer</api/data_types/integer>`, content As `MemoryBlock</api/language/memoryblock>`                                              |         |
| `ReceiveProgress<xojo.net.httpsocket.receiveprogress>`               | bytesReceived As `Int64</api/data_types/additional_types/int64>`, totalBytes As `Int64</api/data_types/additional_types/int64>`, newData As `MemoryBlock</api/language/memoryblock>`        |         |
| `SendProgress<xojo.net.httpsocket.sendprogress>`                     | bytesSent As `Int64</api/data_types/additional_types/int64>`, bytesLeft As `Int64</api/data_types/additional_types/int64>`                                                                  |         |

## Property descriptions

<div id="xojo.net.httpsocket.validatecertificates">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.HTTPSocket.ValidateCertificates

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

When set to True, the socket verifies the supplied certificate for authenticity. The Error event is called if the validation fails. The default value is True.

## Method descriptions

<div id="xojo.net.httpsocket.clearrequestheaders">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.HTTPSocket.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="xojo.net.httpsocket.disconnect">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.HTTPSocket.Disconnect

**Disconnect**

Disconnects the socket.

A disconnected socket is not set to Nil, but is no longer in a useful state. You should create a new socket rather than attempting to re-use a disconnected socket.

<div id="xojo.net.httpsocket.responseheader">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.HTTPSocket.ResponseHeader

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

Gets a response header.

<div id="xojo.net.httpsocket.setrequestcontent">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.HTTPSocket.SetRequestContent

**SetRequestContent**(data As `MemoryBlock</api/language/memoryblock>`, mimeType As `String</api/data_types/string>`)

Sets the content data and content type to be sent to the server.

Sends a POST request, converting JSON data to a MemoryBlock before sending:

``` xojo
Using Xojo.Core
Using Xojo.Data

' Simple data in a Dictionary
Var info As New Dictionary
info.Value("ID") = 123456

' Convert to JSON text
Var json As Text
json = GenerateJSON(info)

' Convert to MemoryBlock  
Var data As MemoryBlock
data = TextEncoding.UTF8.ConvertTextToData(json)

mySocket.SetRequestContent(data, "application/json")
mySocket.Send("POST", "http://127.0.0.1:8080/GetCustomer")
```

To send form information, you build the text yourself:

``` xojo
Using Xojo.Core
Using Xojo.Data

' Build form text
Var formText As Text = "firstName=Bob&lastName=Roberts"

' Convert to MemoryBlock
Var postData As Xojo.Core.MemoryBlock
postData = Xojo.Core.TextEncoding.UTF8.ConvertTextToData(formText)

' POST it
MyHttpSocket.SetRequestContent(postData, "application/x-www-form-urlencoded")
MyHttpSocket.Send("POST", "http://www.webserviceurl.com")
```

## Event descriptions

<div id="xojo.net.httpsocket.authenticationrequired">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.HTTPSocket.AuthenticationRequired

**AuthenticationRequired**(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>`)

Called when the connection requires HTTP basic authentication. Set the name and password and return True.

Specify a name and password:

``` xojo
name = "MyUserName"
password = "MyPassword"
Return True
```

<div id="xojo.net.httpsocket.error">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.HTTPSocket.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://developer.gnome.org/libsoup/stable/libsoup-2.4-soup-status.html)

Display information about the error:

``` xojo
ErrorLabel.Value = err.Reason
```

<div id="xojo.net.httpsocket.filereceived">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.HTTPSocket.FileReceived

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

Called when a download of a file is completed as a result of calling Send and passing a FolderItem.

<div id="xojo.net.httpsocket.headersreceived">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.HTTPSocket.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="xojo.net.httpsocket.pagereceived">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.HTTPSocket.PageReceived

**PageReceived**(URL As `String</api/data_types/string>`, HTTPStatus As `Integer</api/data_types/integer>`, content As `MemoryBlock</api/language/memoryblock>`)

Called when a new page has been retrieved from the server as a result of calling Send.

Convert incoming JSON content from a MemoryBlock into a Dictionary:

``` xojo
Var jsonData As Text
' Convert the content returned from an API from a MemoryBlock to Text.
jsonData = Xojo.Core.TextEncoding.UTF8.ConvertDataToText(content)

' Parse the JSON result into a Dictionary
Var jsonDict As Xojo.Core.Dictionary
jsonDict = Xojo.Data.ParseJSON(jsonData)
```

<div id="xojo.net.httpsocket.receiveprogress">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.HTTPSocket.ReceiveProgress

**ReceiveProgress**(bytesReceived As `Int64</api/data_types/additional_types/int64>`, totalBytes As `Int64</api/data_types/additional_types/int64>`, newData As `MemoryBlock</api/language/memoryblock>`)

Call periodically as data is received.

<div id="xojo.net.httpsocket.sendprogress">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.HTTPSocket.SendProgress

**SendProgress**(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 libsoup 2.4.

In order to use HTTPSocket with TLSv1.2 on Windows 7, KB3140245 needs to be installed using Windows Update and the [DefaultSecureProtocols Registry subkey](https://support.microsoft.com/en-us/help/3140245/update-to-enable-tls-1-1-and-tls-1-2-as-a-default-secure-protocols-in) needs to be configured.

TLSv1.2 is not supported when using <span class="title-ref">Xojo.Net.HTTPSocket</span> on OS X 10.7 and 10.8 due to limitations of those systems.

Use an HTTPSocket when you need to upload or download information on the web. You can download files, communicate with REST web services and other APIs and do any type of HTTP 1.1 communication.

HTTPSocket handles both standard "http" connections and secure "https" connections.

HTTPSocket has a default timeout of 60 seconds, which cannot be changed.

Unlike the classic `URLConnection</api/networking/urlconnection>`, <span class="title-ref">Xojo.Net.HTTPSocket</span> does not support synchronous usage. It only works asynchronously by using the events as described below.

Do not attempt to re-use a socket that is still in use (e.g. directly from the PageReceived or FileReceived events). One solution is to use a separate `Timer</api/language/timer>` that checks if the socket is available before attempting to use it again, but for bests results you will probably want to create a new socket.

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

### Constants

SizeUnknown -1 An unknown number of bytes was received.

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

### Ios and os x information (app transport security)

Starting with iOS 9 and OS X 10.11 (with 2018r4), 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 your App Store submission if you 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.

Apparently there is a bug in iOS that prevents the use of IP addresses in this plist. So to enable http on your local computer for testing use "localhost" rather than "127.0.0.1" and be sure to use "<http://localhost>" in your URLs instead of "<http://127.0.0.1>".

For more information: `Using Non-Secure URLs on macOS and iOS</topics/communication/internet/using_non-secure_urls_on_macos_and_ios>`

## Compatibility

All project types on all supported operating systems.

## See also

`Object</api/data_types/additional_types/object>` parent class; `URLConnection</api/networking/urlconnection>`, `MemoryBlock</api/language/memoryblock>`, `TextEncoding</api/text/encoding_text/textencoding>` classes; `Using a plist</topics/application_structure/ios/using_a_plist>` topic
