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

</div>

Class

# HTTPSocket

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

<div class="warning">

<div class="title">

Warning

</div>

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

</div>

## Description

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

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                            | Type                                                 | Read-Only | Shared |
|-------------------------------------------------|------------------------------------------------------|-----------|--------|
| `Address<httpsocket.address>`                   | `String</api/data_types/string>`                     |           |        |
| `BytesAvailable<httpsocket.bytesavailable>`     | `Integer</api/data_types/integer>`                   | ✓         |        |
| `BytesLeftToSend<httpsocket.byteslefttosend>`   | `Integer</api/data_types/integer>`                   | ✓         |        |
| `ErrorCode<httpsocket.errorcode>`               |                                                      |           |        |
| `Handle<httpsocket.handle>`                     | `Integer</api/data_types/integer>`                   | ✓         |        |
| `HTTPProxyAddress<httpsocket.httpproxyaddress>` | `String</api/data_types/string>`                     |           |        |
| `HTTPProxyPort<httpsocket.httpproxyport>`       | `Integer</api/data_types/integer>`                   |           |        |
| `HTTPStatusCode<httpsocket.httpstatuscode>`     | `Integer</api/data_types/integer>`                   | ✓         |        |
| `IsConnected<httpsocket.isconnected>`           | `Boolean</api/data_types/boolean>`                   | ✓         |        |
| `LocalAddress<httpsocket.localaddress>`         | `String</api/data_types/string>`                     | ✓         |        |
| `NetworkInterface<httpsocket.networkinterface>` | `NetworkInterface</api/networking/networkinterface>` |           |        |
| `Port<httpsocket.port>`                         | `Integer</api/data_types/integer>`                   |           |        |
| `RemoteAddress<httpsocket.remoteaddress>`       | `String</api/data_types/string>`                     | ✓         |        |
| `RequestHeaders<httpsocket.requestheaders>`     | `InternetHeaders</api/networking/internetheaders>`   |           |        |
| `Yield<httpsocket.yield>`                       | `Boolean</api/data_types/boolean>`                   |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                  | Parameters                                                                                                                         | Returns                                            | Shared |
|-------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------|--------|
| `ClearRequestHeaders<httpsocket.clearrequestheaders>` |                                                                                                                                    |                                                    |        |
| `Close<httpsocket.close>`                             |                                                                                                                                    |                                                    |        |
| `Connect<httpsocket.connect>`                         |                                                                                                                                    |                                                    |        |
| `Disconnect<httpsocket.disconnect>`                   |                                                                                                                                    |                                                    |        |
| `EncodeFormData<httpsocket.encodeformdata>`           | Form As `Dictionary</api/language/dictionary>`                                                                                     | `String</api/data_types/string>`                   |        |
| `EndOfFile<httpsocket.endoffile>`                     |                                                                                                                                    | `Boolean</api/data_types/boolean>`                 |        |
| `Flush<httpsocket.flush>`                             |                                                                                                                                    |                                                    |        |
| `Get<httpsocket.get>`                                 | URL As `String</api/data_types/string>`                                                                                            |                                                    |        |
| `GetHeaders<httpsocket.getheaders>`                   | URL As `String</api/data_types/string>`                                                                                            |                                                    |        |
| `Listen<httpsocket.listen>`                           |                                                                                                                                    |                                                    |        |
| `Lookahead<httpsocket.lookahead>`                     | \[Encoding As `TextEncoding</api/text/encoding_text/textencoding>`\]                                                               | `String</api/data_types/string>`                   |        |
| `PageHeaders<httpsocket.pageheaders>`                 |                                                                                                                                    | `InternetHeaders</api/networking/internetheaders>` |        |
| `Poll<httpsocket.poll>`                               |                                                                                                                                    |                                                    |        |
| `Post<httpsocket.post>`                               | URL As `String</api/data_types/string>`                                                                                            |                                                    |        |
| `Purge<httpsocket.purge>`                             |                                                                                                                                    |                                                    |        |
| `Read<httpsocket.read>`                               | Count As `Integer</api/data_types/integer>`, \[Enc As `TextEncoding</api/text/encoding_text/textencoding>`\]                       | `String</api/data_types/string>`                   |        |
| `ReadAll<httpsocket.readall>`                         | \[Encoding As `TextEncoding</api/text/encoding_text/textencoding>`\]                                                               | `String</api/data_types/string>`                   |        |
| `SendRequest<httpsocket.sendrequest>`                 | Method As `String</api/data_types/string>`, URL As `String</api/data_types/string>`, Timeout As `Integer</api/data_types/integer>` | `String</api/data_types/string>`                   |        |
| `SetFormData<httpsocket.setformdata>`                 | Form As `Dictionary</api/language/dictionary>`                                                                                     |                                                    |        |
| `SetPostContent<httpsocket.setpostcontent>`           | Content As `String</api/data_types/string>`, ContentType As `String</api/data_types/string>`                                       |                                                    |        |
| `SetRequestContent<httpsocket.setrequestcontent>`     | Content As `String</api/data_types/string>`, ContentType As `String</api/data_types/string>`                                       |                                                    |        |
| `SetRequestHeader<httpsocket.setrequestheader>`       | Name As `String</api/data_types/string>`, Value As `String</api/data_types/string>`                                                |                                                    |        |
| `Write<httpsocket.write>`                             | Data As `String</api/data_types/string>`                                                                                           |                                                    |        |

## Events

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                                  | Parameters                                                                                                                                                                                                                                                 | Returns                            |
|-----------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|
| `AuthenticationRequired<httpsocket.authenticationrequired>`           | Realm As `String</api/data_types/string>`, Headers As `InternetHeaders</api/networking/internetheaders>`, `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>` |
| `Connected<httpsocket.connected>`                                     |                                                                                                                                                                                                                                                            |                                    |
| `DownloadComplete<httpsocket.downloadcomplete>`                       | URL As `String</api/data_types/string>`, HTTPStatus As `Integer</api/data_types/integer>`, Headers As `InternetHeaders</api/networking/internetheaders>`, File As `FolderItem</api/files/folderitem>`                                                      |                                    |
| `HeadersReceived<httpsocket.headersreceived>`                         | Headers As `InternetHeaders</api/networking/internetheaders>`, HTTPStatus As `Integer</api/data_types/integer>`                                                                                                                                            |                                    |
| `PageReceived<httpsocket.pagereceived>`                               | URL As `String</api/data_types/string>`, HTTPStatus As `Integer</api/data_types/integer>`, Headers As `InternetHeaders</api/networking/internetheaders>`, Content As `String</api/data_types/string>`                                                      |                                    |
| `ProxyAuthenticationRequired<httpsocket.proxyauthenticationrequired>` | Realm As `String</api/data_types/string>`, Headers As `InternetHeaders</api/networking/internetheaders>`, `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>` |
| `ReceiveProgress<httpsocket.receiveprogress>`                         | BytesReceived As `Integer</api/data_types/integer>`, TotalBytes As `Integer</api/data_types/integer>`, NewData As `String</api/data_types/string>`                                                                                                         |                                    |
| `SendProgress<httpsocket.sendprogress>`                               | BytesSent As `Integer</api/data_types/integer>`, BytesLeft As `Integer</api/data_types/integer>`                                                                                                                                                           |                                    |

## Property descriptions

<div id="httpsocket.address">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.Address

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

The TCP/IP address to try to connect to.

In this example, the address has been entered into a `TextField</api/user_interface/desktop/desktoptextfield>`.

``` xojo
TCPSocket1.Address = TextField1.Text
```

<div id="httpsocket.bytesavailable">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.BytesAvailable

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

The number of bytes of data are available in the internal receive buffer.

This property is read-only.

``` xojo
TextField1.Text = Me.BytesAvailable.ToString
```

<div id="httpsocket.byteslefttosend">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.BytesLeftToSend

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

The number of bytes left in the queue remaining to be sent.

This property is read-only.

This enables you to create a synchronous socket without needing to subclass it.

``` xojo
TextField1.Text = Me.BytesLeftToSend.ToString
```

<div id="httpsocket.errorcode">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.ErrorCode

**ErrorCode** As

A special case of LastErrorCode.

Returns the same as `LastErrorCode<socketcore.error>` except for these two conditions:

\# If Get/Post/GetHeaders/SendRequest times out, then ErrorCode = -1 \# When calling Get (the overloaded method that accepts a FolderItem as a parameter), if the file is a directory or could not be created then ErrorCode = 1

<div id="httpsocket.handle">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.Handle

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

This is the socket's internal descriptor and it can be used with `Declare</api/language/declare>` statements.

This property is read-only.

- On Windows, Handle is a Socket, suitable for use in `Declares</api/language/declare>` on Windows.
- On macOS and Linux, Handle is a UNIX socket descriptor.

The descriptor is platform-specific. If *Handle* is less than zero, the descriptor is not available.

<div id="httpsocket.httpproxyaddress">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.HTTPProxyAddress

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

The proxy address; required only if you are connecting via proxy.

This example specifies the proxy address. The proxy serves as a “middleman" to provide additional security or anonymity.

``` xojo
Me.HTTPProxyAddress = "130.25.0.1"
```

<div id="httpsocket.httpproxyport">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.HTTPProxyPort

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

The proxy port; required only if you are connecting via proxy.

This example sets the proxy port.

``` xojo
Me.HTTPProxyPort = 6960
```

<div id="httpsocket.httpstatuscode">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.HTTPStatusCode

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

Returns the resulting code from the server. This function provides the status code when the socket is used in synchronous mode.

This property is read-only.

This code reads the HTTP status code.

``` xojo
TextField1.Text = Str(Me.HTTPStatusCode)
```

<div id="httpsocket.isconnected">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.IsConnected

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

Indicates whether the socket is currently connected.

This property is read-only.

For `TCPSockets</api/networking/tcpsocket>`, a connection means you can send and receive data and are connected to a remote machine. For `UDPSockets</api/networking/udpsocket>`, this means that you are bound to the port and are able to send, receive, join or leave multicast groups, or set socket options.

``` xojo
If EasyUDPSocket1.IsConnected Then
  ' proceed using the connection
Else
  MessageBox("Connection failed!")
End If
```

<div id="httpsocket.localaddress">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.LocalAddress

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

The local IP address of the computer.

This property is read-only.

``` xojo
Var localIP As String = Socket1.LocalAddress
```

<div id="httpsocket.networkinterface">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.NetworkInterface

**NetworkInterface** As `NetworkInterface</api/networking/networkinterface>`

Specifies which network interface the socket should use when binding.

You can get the network interface(s) of the user's computer by calling the `GetNetworkInterface<system.networkinterface>` method of the `System</api/os/system>` module.

Leaving this property set to `Nil</api/language/nil>` will use the currently selected interface. In the case of `UDPSockets</api/networking/udpsocket>`, if you assign a non-`Nil</api/language/nil>` value, the socket may not be able to receive broadcast messages. The behavior is OS-dependent; it appears to work on Windows but not on other supported operating systems. If you wish to send broadcast packets out, then you should not bind to a specific interface because the behavior is undefined.

This example specifies that the `TCPSocket</api/networking/tcpsocket>` will use the first Network Interface on the user's computer.

``` xojo
TCPSocket1.NetworkInterface = System.NetworkInterface(0)
```

<div id="httpsocket.port">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.Port

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

The port to bind on or connect to.

On most operating systems, attempting to bind to a port less than 1024 causes a `Error<socketcore.error>` event to fire with an error number 107 unless the application is running with administrative permissions. This is due to security features built into the underlying OS.

You need to set the port property explicitly before any call to Listen or Connect as the Port property will be modified to reflect what the actual bound port is during the various stages of operation.

For instance, if you listen on port 8080 and a connection comes in, you can check the Port property to ensure that you're still listening on port 8080 (that the port hasn't been hijacked). Or, if you connect to a socket on port 8080, once the connection occurs, you can check to see what port the OS has bound you to. This will be a random-seeming port number.

This trick can be very useful when you do things like Listen on port 0. In that case, the OS will pick a port for you and listen on it. Then you can check the Port property to see which port the OS picked. This functionality is used for various protocols, such as FTP.

This example sets the Port to 8080.

``` xojo
TCPSocket1.Port = 8080
```

<div id="httpsocket.remoteaddress">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.RemoteAddress

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

The address of the remote machine you are connected to.

This property is read-only.

Use this instead of the Address property to determine the address of the machine you are actually connected to.

This example reports the address of the remote machine that the user is connected to. It is in the Connected event.

``` xojo
TextField1.Text = Me.RemoteAddress
```

<div id="httpsocket.requestheaders">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.RequestHeaders

**RequestHeaders** As `InternetHeaders</api/networking/internetheaders>`

Request headers are sent to the server along with the action (GET, POST, etc.). They can contain data that the server might use to process your request. Some examples of common request headers are for things such as referring pages, the client name, OS CPU, and so forth.

The default headers are:

Accept:*/*

Accept-Language:en

Connection:close

<div id="httpsocket.yield">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.Yield

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

When you are using synchronous HTTP, your application may need to wait a noticeable amount of time to get or post a page. Setting *Yield* to `True</api/language/true>` allows for events and other code to execute while waiting for a page. *Yield* is relevant when you pass the optional *Timeout* parameter with Get or GetHeaders. Set *Yield* to `True</api/language/true>` just prior to a call to any of these methods.

## Method descriptions

<div id="httpsocket.clearrequestheaders">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.ClearRequestHeaders

**ClearRequestHeaders**

Clears all of the set request headers. See the description of the SetRequestHeaders method for information on headers.

<div id="httpsocket.close">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.Close

**Close**

Closes the socket's connection, closes any connections the socket may have, and resets the socket.

The only information that is retained after calling Close is the socket's port, address (in the case of `TCPSockets</api/networking/tcpsocket>`), LastErrorCode properties, and data left in the socket's receive buffer. All other information is discarded.

This example closes the `EasyTCPSockets</api/networking/easytcpsocket>` that were open. The sockets were added to the main window.

``` xojo
Connector.Close
Listener.Close
```

<div id="httpsocket.connect">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.Connect

**Connect**

Attempts to connect.

For `TCPSockets</api/networking/tcpsocket>`, the address and port properties must be set. For `UDPSockets</api/networking/udpsocket>`, the port property must be set. The Connect method binds a socket to a port. After calling Connect, the Port property will report the actual port you are bound to.

<div id="httpsocket.disconnect">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.Disconnect

**Disconnect**

Disconnects the socket, resets it, and fires a `SocketCore</api/networking/socketcore>` Error event with a 102 error to let you know that the socket has been disconnected.

This example disconnects the `EasyTCPSockets</api/networking/easytcpsocket>` that were opened.

``` xojo
Connector.Disconnect
Listener.Disconnect
```

<div id="httpsocket.encodeformdata">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.EncodeFormData

**EncodeFormData**(Form As `Dictionary</api/language/dictionary>`) As `String</api/data_types/string>`

Takes the key/value pairs from the passed `Dictionary</api/language/dictionary>` and formats them into a URL-encoded `String</api/data_types/string>`. The result can then be used in the URL to send data to a form with a GET action or as content for a POST.

<div id="httpsocket.endoffile">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.EndOfFile

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

Returns `True</api/language/true>` when there's no more data left to read.

This code reads the rows and columns of data from a tab-delimited text file into a `ListBox</api/deprecated/listbox>`:

``` xojo
Var f As FolderItem
Var textInput As TextInputStream
Var rowFromFile As String

f = FolderItem.ShowOpenFileDialog("text/plain") ' defined as a FileType
If f <> Nil Then
  textInput = TextInputStream.Open(f)
  textInput.Encoding = Encodings.UTF8

  Do
    rowFromFile = textInput.ReadLine
    Var values() As String = rowFromFile.Split(Chr(9))
    ListBox1.ColumnCount = values.Count
    ListBox1.AddRow("")
    Var col As Integer
    For Each value As String In values
      ListBox1.CellTextAt(ListBox1.LastAddedRowIndex, col) = value
      col = col + 1
    Next
  Loop Until textInput.EndOfFile

  textInput.Close
End If
```

This example reads each pair of bytes from a file and writes them in reverse order to a new file. The user chooses the source file using the Open-file dialog box and saves the new file using the Save as dialog box. The EOF property is used to terminate the `Do...Loop</api/language/loops/do...loop>`.

``` xojo
Var readFile As FolderItem = FolderItem.ShowOpenFileDialog("text")
If readFile <> Nil Then
  Var ReadStream As BinaryStream = BinaryStream.Open(readFile, False)
  ReadStream.LittleEndian = True
  Var writeFile As FolderItem = FolderItem.ShowSaveFileDialog("", "")
  If writeFile <> Nil Then
    Var writeStream As BinaryStream = BinaryStream.Create(writeFile, True)
    writeStream.LittleEndian = True
    Do Until ReadStream.EndOfFile
      writeStream.WriteInt8(ReadStream.ReadInt8)
    Loop
    writeStream = Nil
  End If
  readStream = Nil
End If
```

<div id="httpsocket.flush">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.Flush

**Flush**

Immediately sends the contents of internal write buffers to disk or to the output stream.

This function can be useful in point-to-point communication over sockets and similar connections: To optimize for transmission performance, some types of output streams try to collect small pieces of written data into one larger piece for sending instead of sending each piece out individually. By calling Flush, the data collection is stopped and the data is sent without further delay, reducing latency.

When using this on a stream that ends up as a file on disk, it is useful, too: Any short parts of previously written data are written to disk right away, ensuring the data is actually on disk if the application terminates abruptly, e.g. due to a crash.

Avoid calling this method too often. For example, do not call it between successive Write calls because you'll slow down performance without getting much benefit.

A typical use case would look like this:

``` xojo
mySocket.Write("you typed: ")
mySocket.Write(key)
mySocket.Write(".")
mySocket.Flush
```

<div id="httpsocket.get">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.Get

**Get**(URL As `String</api/data_types/string>`)

Synchronously downloads the content from the URL directly to the `FolderItem</api/files/folderitem>`. When the download has finished, `True</api/language/true>` is returned if successful, `False</api/language/false>` if there was an error. *Timeout* is the number of seconds to wait for the result. `ErrorCode<httpsocket.errorcode>` is -1 if the *Timeout* value is reached.

For the synchronous version of these methods, set the Yield property to `True</api/language/true>` to allow for background activities while waiting.

<div id="httpsocket.getheaders">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.GetHeaders

**GetHeaders**(URL As `String</api/data_types/string>`)

Synchronously Requests only the page headers from the specified URL. The headers are return as an `InternetHeaders</api/networking/internetheaders>`.

When running synchronously, set the `Yield<httpsecuresocket.yield>` property to `True</api/language/true>` to allow for background activities while waiting.

<div id="httpsocket.listen">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.Listen

**Listen**

Attempts to listen for incoming connections on the currently specified port.

After calling Listen, the Port property will report the actual port you are bound to.

<div id="httpsocket.lookahead">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.Lookahead

**Lookahead**(\[Encoding As `TextEncoding</api/text/encoding_text/textencoding>`\]) As `String</api/data_types/string>`

Returns a `String</api/data_types/string>`, containing the data that is available in the internal queue without removing it.

The optional *Encoding* parameter enables you to specify the text encoding of the data to be returned. The default is `Nil</api/language/nil>`. Use the `Encodings</api/text/encoding_text/encodings>` module to specify an encoding.

This example adds the contents of the internal queue to a `TextArea</api/deprecated/textarea>`. The Listener `EasyTCPSocket</api/networking/easytcpsocket>` has been added to the window.

``` xojo
TextArea1.AddText(listener.Lookahead)
```

<div id="httpsocket.pageheaders">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.PageHeaders

**PageHeaders** As `InternetHeaders</api/networking/internetheaders>`

Provides access to the headers received from the server. This can be used to access the headers in synchronous mode.

<div id="httpsocket.poll">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.Poll

**Poll**

Polls the socket manually, which allows a socket to be used synchronously.

The `EasyTCPSocket</api/networking/easytcpsocket>` "Listener" has been added to the window.

``` xojo
Listener.Poll
```

<div id="httpsocket.post">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.Post

**Post**(URL As `String</api/data_types/string>`)

Synchronously issues a POST command to the URL and downloads the response directly to the FolderItem. When the download has finished, `True</api/language/true>` is returned if successful, `False</api/language/false>` if there was an error. *TimeOut* is the number of seconds to wait for the result.

For the synchronous versions of this method, set the `Yield<httpsocket.yield>` property to `True</api/language/true>` to allow for background activities while waiting.

This example does a synchronous POST to a service that returns what you POSTed to it as JSON:

``` xojo
Var d As New Dictionary

d.Value("Test") = "TestValue"
d.Value("Value2") = "Testing"

Socket.SetFormData(d)

' This service returns the post data as the result
Var result As String
result = Socket.Post("http://httpbin.org/post", 30) ' Synchronous

result = DefineEncoding(result, Encodings.UTF8)

MessageBox(result)
```

To do this asynchronous, call Post without a timeout:

``` xojo
Var d As New Dictionary

d.Value("Test") = "TestValue"
d.Value("Value2") = "Testing"

Socket.SetFormData(d)

' This service returns the post data as the result
Socket.Post("http://httpbin.org/post")
```

The results will be available in the PageReceived event handler in the content parameter.

``` xojo
Sub PageReceived(url As String, httpStatus As Integer, headers As InternetHeaders, content As String)
  Var data As String
  data = DefineEncoding(content, Encodings.UTF8)

  ResultArea.Value = data
End Sub
```

<div id="httpsocket.purge">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.Purge

**Purge**

Removes all data from the socket's internal receive buffer. It does not affect the socket's internal send buffer.

``` xojo
Listener.Purge
```

<div id="httpsocket.read">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.Read

**Read**(Count As `Integer</api/data_types/integer>`, \[Enc As `TextEncoding</api/text/encoding_text/textencoding>`\]) As `String</api/data_types/string>`

Reads *Count* bytes from the input stream and returns a `String</api/data_types/string>`.

If provided, the optional parameter *Enc* specifies the text encoding to be defined for the `String</api/data_types/string>` to be read.

If *Count* is higher than the amount of bytes currently available in the stream, all available bytes will be returned. Therefore, make sure to always consider the case that you get less than you requested. To see if you received all requested bytes, check the returned string's `String.Bytes<string.bytes>` property (avoid using `Length<binarystream.length>` as it may give a different number if the encoding is not nil).

If not enough memory is available, you get back an empty string.

This example reads the first 1000 bytes from a `BinaryStream</api/files/binarystream>`.

``` xojo
Var readFile As FolderItem = FolderItem.ShowOpenFileDialog("text/plain")
If readFile <> Nil Then
  Var ReadStream As BinaryStream = BinaryStream.Open(readFile, False)
  ReadStream.LittleEndian = True
  TextArea1.Text = ReadStream.Read(1000, Encodings.UTF8)
End If
```

<div id="httpsocket.readall">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.ReadAll

**ReadAll**(\[Encoding As `TextEncoding</api/text/encoding_text/textencoding>`\]) As `String</api/data_types/string>`

Reads all the data from the internal buffer.

This example reads all the data in the buffer into a `TextArea</api/deprecated/textarea>`.

``` xojo
TextField1.AddText(listener.ReadAll)
```

<div id="httpsocket.sendrequest">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.SendRequest

**SendRequest**(Method As `String</api/data_types/string>`, URL As `String</api/data_types/string>`, Timeout As `Integer</api/data_types/integer>`) As `String</api/data_types/string>`

Allows the user to synchronously send a request using an HTTP method other than GET or POST. Supply the method as a `String</api/data_types/string>`, URL as a `String</api/data_types/string>` and a `FolderItem</api/files/folderitem>`. Return a `Boolean</api/data_types/boolean>` to indicate if it was successful. Data is saved to the FolderItem.

Common others methods are OPTIONS, HEAD, PUT, DELETE, TRACE and CONNECT as per RFC 2616 describing the HTTP 1.1 protocol.

<div id="httpsocket.setformdata">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.SetFormData

**SetFormData**(Form As `Dictionary</api/language/dictionary>`)

Takes the key/value pairs from the passed `Dictionary</api/language/dictionary>` and converts it to a URL-encoded `String</api/data_types/string>`.

<div id="httpsocket.setpostcontent">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.SetPostContent

**SetPostContent**(Content As `String</api/data_types/string>`, ContentType As `String</api/data_types/string>`)

Sets the content data and content type to be sent to the server for a POST command.

<div id="httpsocket.setrequestcontent">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.SetRequestContent

**SetRequestContent**(Content As `String</api/data_types/string>`, ContentType As `String</api/data_types/string>`)

Sets the content data and content type to be sent to the server for any command except HEAD.

If you will be reusing a socket without using the `New</api/language/new>` operator, you must clear this value for requests that do not have content associated with them. For instance, If you do a POST with content followed by a GET that should not have content, you should set the content to an empty string.

Set request content:

``` xojo
Dim data As String = "ID=1234"
MySocket.SetRequestContent(data, "application/x-www-form-urlencoded")
```

<div id="httpsocket.setrequestheader">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.SetRequestHeader

**SetRequestHeader**(Name As `String</api/data_types/string>`, Value As `String</api/data_types/string>`)

Sets the value of a request header.

Request headers are sent to the server along with the action (GET, POST, etc.). They can contain data that the server might use to process your request. Some examples of common request headers are for things such as referring pages, the client name, OS CPU, and so forth.

This example changes the user agent:

``` xojo
HTTPSocket1.SetRequestHeader("User-Agent:", "CustomUserAgentString")
```

<div id="httpsocket.write">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.Write

**Write**(Data As `String</api/data_types/string>`)

Writes the passed data to the output stream.

Note that in order to make sure that the data actually ends up on disk or gets sent to the socket it is connected to, the stream must either get closed or the `Flush<writeable.flush>` method be called. Otherwise, the data, if small, may end up temporarily in a write buffer before either a certain time has passed or more data is written. This buffering increases performance when writing lots of small pieces of data, but may be causing unwanted delays when another process, e.g. the other end of a socket connection, is waiting for the data. Consider calling the `Flush<writeable.flush>` method to reduce latencies that this buffering may cause in such cases.

If Write fails, an `IOException</api/exceptions/ioexception>` will be raised.

This example displays the Save As dialog box and writes the contents of the TextArea1 to a text file.

``` xojo
Var f As FolderItem
Var stream As BinaryStream
f = FolderItem.ShowSaveFileDialog(FileTypes1.Text, "Untitled.txt")
If f<> Nil Then
  stream = BinaryStream.Create(f, True)
  stream.Write(TextArea1.Text)
  stream.Close
End If
```

## Event descriptions

<div id="httpsocket.authenticationrequired">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.AuthenticationRequired

**AuthenticationRequired**(Realm As `String</api/data_types/string>`, Headers As `InternetHeaders</api/networking/internetheaders>`, `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>`

Executes when a site that requires authentication connects. AuthenticationRequired also supports Digest authentication.

<div id="httpsocket.connected">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.Connected

**Connected**

Executes when the connection is established with the server.

<div id="httpsocket.downloadcomplete">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.DownloadComplete

**DownloadComplete**(URL As `String</api/data_types/string>`, HTTPStatus As `Integer</api/data_types/integer>`, Headers As `InternetHeaders</api/networking/internetheaders>`, File As `FolderItem</api/files/folderitem>`)

Executes when a download is complete after using the Get or Post methods and passing the optional parameter. URL contains the URL that was downloaded. *File* is the `FolderItem</api/files/folderitem>` the data was downloaded to, and *Headers* is a dictionary of the HTTP headers that were returned by the server. The HTTPStatus code is also passed to this event. These codes are used for messages such as "Page not found" (error 404), and so forth.

<div id="httpsocket.headersreceived">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.HeadersReceived

**HeadersReceived**(Headers As `InternetHeaders</api/networking/internetheaders>`, HTTPStatus As `Integer</api/data_types/integer>`)

Executes when the headers have been retrieved from the server.

<div id="httpsocket.pagereceived">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.PageReceived

**PageReceived**(URL As `String</api/data_types/string>`, HTTPStatus As `Integer</api/data_types/integer>`, Headers As `InternetHeaders</api/networking/internetheaders>`, Content As `String</api/data_types/string>`)

Executes when a new page has been retrieved from the server. It provides the URL that was requested and the HTTP headers from the web server. The HTTPStatus code is also passed to this event. These codes are used for messages such as "Page not found" (error 404), and so forth.

<div id="httpsocket.proxyauthenticationrequired">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.ProxyAuthenticationRequired

**ProxyAuthenticationRequired**(Realm As `String</api/data_types/string>`, Headers As `InternetHeaders</api/networking/internetheaders>`, `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>`

Executes when a site that requires via proxy authentication connects. ProxyAuthenticationRequired also supports Digest authentication.

<div id="httpsocket.receiveprogress">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.ReceiveProgress

**ReceiveProgress**(BytesReceived As `Integer</api/data_types/integer>`, TotalBytes As `Integer</api/data_types/integer>`, NewData As `String</api/data_types/string>`)

Provides the current number of bytes received and the total number of bytes (if available). It executes periodically during the download process.

<div id="httpsocket.sendprogress">

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

</div>

<div class="rst-class">

forsearch

</div>

HTTPSocket.SendProgress

**SendProgress**(BytesSent As `Integer</api/data_types/integer>`, BytesLeft As `Integer</api/data_types/integer>`)

Occurs when your network provider queues your data in chunks and is about to send the next chunk.

The parameters indicate the amount of progress that has been made during the send. Returns a `Boolean</api/data_types/boolean>`.

Returning `True</api/language/true>` from this event causes the send to be cancelled. This does not close the socket's connection; it only clears the buffer. After all of the data has been transferred you will get a final SendProgress event followed by a `SendComplete<socketcore.sendcomplete>` event.

*bytesSent* is the number of bytes that were sent in the chunk, not the total number of bytes sent.

## Notes

<div class="note">

<div class="title">

Note

</div>

If you need HTTP 1.1 support, use `URLConnection</api/networking/urlconnection>` instead.

</div>

Use the <span class="title-ref">HTTPSocket</span> class to send and receive data via the HTTP protocol. Since this is a subclass of the `TCPSocket</api/networking/tcpsocket>` class, all the standard socket APIs are also available. To perform secure communications (via HTTPS), use the `URLConnection</api/networking/urlconnection>` class instead. It is otherwise identical, except that it is subclassed from `SSLSocket</api/networking/sslsocket>` instead of `TCPSocket</api/networking/tcpsocket>`. This makes all the options for encrypted communications available to `URLConnection</api/networking/urlconnection>` objects.

If you use a constructor in a subclass of <span class="title-ref">HTTPSocket</span>, you must call the super class's constructor in your subclass's constructor. The subclass fail when you try to download.

When using the optional Timeout parameter of the Get or GetHeaders methods the page will be received or posted in a synchronous manner. That is, your app will wait until the page has been received or posted before it proceeds. If Timeout is set to zero, the socket will wait indefinitely or until it receives an error.

To use synchronous mode, pass the optional parameter. For example,

``` xojo
Dim http As New HTTPSocket
MsgBox(http.Get("http://www.example.com", 30))
```

When using synchronous mode, you can set the Yield property to `True</api/language/true>` to tell the socket to yield time to other events and code to execute while waiting. Insert a statement such as:

``` xojo
http.Yield = True
```

to allow background processes to execute while waiting.

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

### App transport security

Starting with OS X 10.11 and 2018r4, your apps 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". You can work around this by providing a plist with your app to indicate what non-secure URLs you are using. For more information:

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

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

### Xojo cloud

Web apps running on Xojo Cloud first have to use the `FirewallPort</api/xojocloud/firewallport>` class to open the port used to connect to an outside web server.

## Sample code

The following example retrieves the specified URL synchronously:

``` xojo
Dim socket1 As New HTTPSocket
Dim data As String = socket1.Get("http://www.example.com/", 30)
```

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

For asynchronously transfers you need to subclass <span class="title-ref">HTTPSocket</span>, call get without timeout parameter and get result in `PageReceived<httpsocket.pagereceived>` event.

The following example posts a simple form:

``` xojo
Dim form As Dictionary
Dim socket1 As New HTTPSocket

' create and populate the form object
form = New Dictionary
form.Value("firstname") = "Bob"
form.Value("lastname") = "Brown"

' setup the socket to POST the form
socket1.SetFormData(form)
socket1.Post("http://www.myformlocation.com/form.php")
```

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

To send one or more cookies with an HTTP request:

``` xojo
socket.SetRequestHeader("Cookie", Join(Array(cookie1, cookie2), "; "))
```

## Compatibility

All project types on all supported operating systems.

## See also

`TCPSocket</api/networking/tcpsocket>` parent class; `URLConnection</api/networking/urlconnection>`, `URLConnection</api/networking/urlconnection>`, `SocketCore</api/networking/socketcore>`, `TCPSocket</api/networking/tcpsocket>`, `URLConnection</api/networking/urlconnection>` classes.
