HTTP Login and xml downloads


I want to create a program that downloads xml files from a website. The problem is that I have to get the program to log the user in to the website.
Can anyone give me any help on how I can get my program to pass the username and password to the website and somehow keep the cookie the website sends back? I can log in on the website (and read the sessionid from the header), but when I send the download request for the xml file, the website doesn’t recognize me anymore and I can’t continue the download.

Thanks in advance,

Use the HTTPSocket and implement the authenticationrequired event to pass the username & password.



Use Fiddler or a similar tool to sniff the traffic. See how the login info is sent, which cookies are needed to be considered logged in, etc, cause you might be missing a header.

Then try to replicate it with HTTPSocket.

Theoritical example code as I don’t have Xojo open:

Dim form as new Dictionary // stores username and password
Dim http as new HTTPSocket
Dim source as String // source = the html source of the website, in case we need some info from the source.

http.Yield = True // to not freeze the GUI

form.Value(“username”) = “myusername”
form.Value(“password”) = “12345678”

http.SetFormData(form) // set the form data, so that when you do a Post, it sends the login info (username, password)

source = http.Post(“”,30)

// here we grab the cookies
Dim myCookies() as String
for i as Integer=0 to http.PageHeaders.Count-1
if http.PageHeaders.Name(i) = “Set-Cookie” Then
End if
next i


http.SetRequestHeader(“Cookie”, Join(myCookies, "; "))

source = http.Get(“”,30) // we are logged in now

Hi Ashot!
Thank you for your answer. With your very well commented example source code I was able to solve my problem. The snippets “here we grab the cookies” and "http.SetRequestHeader(“Cookie”, Join(myCookies, "; “))” has helped me a lot. I am thrilled, thank you! The tip with the Sniffer tool was also very good. I’ve found for my Mac Charles Proxy, a very useful tool.
Thanks also to Wayne for the quick reply.