# Access a site from a web app

**URL:** <https://forum.xojo.com/t/access-a-site-from-a-web-app/88713>\
**Category:** Web\
**Created:** [August 4, 2026, 8:07pm UTC](https://forum.xojo.com/t/access-a-site-from-a-web-app/88713 "2026-08-04T20:07:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bob\_Gordon](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/898d66/32.png) [@Bob\_Gordon](https://forum.xojo.com/u/Bob_Gordon)\
**Post date:** [August 4, 2026, 8:07pm UTC](https://forum.xojo.com/t/access-a-site-from-a-web-app/88713/1 "2026-08-04T20:07:47Z")

</div>

I need to be able to retrieve data from a website from a Xojo web app. It’s an XML file. The goal is to have it downloaded to the user’s computer. WebHTMLViewer has a loadURL method, but I don’t need to show the site.

Is this possible?

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [August 4, 2026, 8:30pm UTC](https://forum.xojo.com/t/access-a-site-from-a-web-app/88713/2 "2026-08-04T20:30:37Z")

</div>

look at xojo examples using urlconnection

> **[URLConnection — Xojo documentation](https://documentation.xojo.com/api/networking/urlconnection.html#urlconnection-filereceived)**
>
> URLConnection.AuthenticationRequested

---

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [August 5, 2026, 12:18pm UTC](https://forum.xojo.com/t/access-a-site-from-a-web-app/88713/3 "2026-08-05T12:18:47Z")

</div>

Here is what I use to get a web file as a FolderItem or as a String:

```Xojo
Protected Function getURLConnectionFolderItem(URLConnectionHost As String, f As FolderItem, URLConnectionTimeOut As Integer = 10) As FolderItem
  Var tempURLConnection As New URLConnection
  Var MIMEType As String = "application/json"
  Var HTTPStatusCode As Integer
  
  If f = Nil Or URLConnectionHost = "" Or (URLConnectionHost.left(7) <> "http://" And URLConnectionHost.left(8) <> "https://") Then
    Return Nil
  End If
  
  Try 'network timeout causes exception!
    #If TargetWindows Or TargetLinux Then
      tempURLConnection.AllowCertificateValidation = False 'Windows gets a Security Error if True
    #EndIf
    tempURLConnection.SendSync("GET", URLConnectionHost, f, URLConnectionTimeOut)
    HTTPStatusCode = tempURLConnection.HTTPStatusCode
    tempURLConnection.Disconnect
    
  Catch Error
    Return Nil
  End Try
  
  If f <> Nil And f.Exists Then 'And HTTPStatusCode = 0
    Return f
  Else
    Return Nil
  End If
      
End Function

Protected Function getURLConnectionFolderItemString(URLConnectionHost As String, URLConnectionTimeOut As Integer = 30) As String
  Var f As FolderItem = CommonFolders.getDownloadFolderItem("Temp.dat", True, True) 'get a temp FolderItem
  
  f = getURLConnectionFolderItem(URLConnectionHost, f, URLConnectionTimeOut)
  
  If f <> Nil And f.Exists Then
    Return CommonFolders.getFileToString(f, True).DefineEncoding(Encodings.UTF8) 'read FolderItem as Binary String
  Else
    Return ""
  End If
      
End Function

Protected Function getFileToString(f As FolderItem, asBinary As Boolean = False) As String
  'converts the contents of a file to a string
  'CopyFile creates a read only file, whereas this routine creates a file that can be written to
  Var tempTextInputStream As TextInputStream
  Var tempBinaryStream As BinaryStream
  Var returnString As String
  
  If f = Nil Or Not f.Exists Then
    Return "" ' "0"
  Else
    If asBinary Then
      tempBinaryStream = BinaryStream.Open(f)
      returnString = tempBinaryStream.Read(tempBinaryStream.Length)
      'tempBinaryStream.Flush
      tempBinaryStream.Close
      Return returnString
      
    Else
      tempTextInputStream = TextInputStream.Open(f)
      returnString = tempTextInputStream.ReadAll
      tempTextInputStream.Close
      Return returnString
    End If
  End If
      
End Function

```
