-
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Andrew Lambert edited this page Nov 27, 2022
·
4 revisions
The CookieEngine class implements web browser-like HTTP cookie management (a "cookie engine"). It can be used with the Realstudio HTTPSocket, Xojo.Net.HttpSocket, Xojo URLConnection, or any other HTTP client.
If you are on an older version of Xojo (or still using RealStudio) then you must delete the ParseResponseHeaders(URL As String, ResponseHeaders As Iterable)
method before using this class. Leave the other ParseResponseHeaders
method intact.
Dim engine As New CookieEngine ' create a new, empty CookieEngine
engine.Load(GetFolderItem("cookies.txt")) ' optionally load cookies from a file
engine.SetCookie("foo", "bar", ".example.com") ' set cookies manually
Dim connection As New URLConnection
Dim url As String = "https://www.example.com/"
' before a request call GenerateRequestHeader() to get a Cookie: header for the URL
Dim cookie As String = engine.GenerateRequestHeader(url)
If cookie <> "" Then connection.RequestHeader("Cookie") = cookie
Call connection.SendSync("GET", url, 10)
' after a request call ParseResponseHeaders() to collect any cookies that were set
engine.ParseResponseHeaders(url, connection.ResponseHeaders)
' optionally save cookies to a file
engine.Save(GetFolderItem("cookies.txt"))
Dim engine As New CookieEngine ' create a new, empty CookieEngine
engine.Load(GetFolderItem("cookies.txt")) ' optionally load cookies from a file
engine.SetCookie("foo", "bar", ".example.com") ' set cookies manually
Dim connection As New HTTPSecureSocket
Dim url As String = "https://www.example.com/"
' before a request call GenerateRequestHeader() to get a Cookie: header for the URL
Dim cookie As String = engine.GenerateRequestHeader(url)
If cookie <> "" Then connection.SetRequestHeader("Cookie", cookie)
Call connection.Get(url, 10)
' after a request call ParseResponseHeaders() to collect any cookies that were set
engine.ParseResponseHeaders(url, connection.PageHeaders)
' optionally save cookies to a file
engine.Save(GetFolderItem("cookies.txt"))
Wiki home | Project page | Bugs | Become a sponsor
Text and code examples are Copyright ©2021-24 Andrew Lambert, offered under the CC BY-SA 3.0 License.