HTTPSecureSocket Example??

Hi everyone!

Is there a definitive Xojo HTTPSecureSocket example project somewhere out there so I can see how it’s done? I want to retrieve a webpage from a standard secure server (I have a login & password ) so I can query the webpage for key text using RegEx.

I want to streamline some data entry that doesn’t need to be done twice. Querying the server with valid credentials will enable me to do that.

Unfortunately I can’t direct you to the site in question (it’s government), but it’s just a standard secure server accessible via any standard web browser Safari/IE/Chrome etc etc…

Cheers
Grant

Dim http as new HTTPSecureSocket

http.ConnectionType = 3

Dim html as String

html = http.Get(“https://example.com”,30)

// html has the info you need

Thanks Ashot, but what about the required username & password?

Cheers
Grant

You set the username and password in the HTTPSecureSocket.AuthenticationRequired event handler.

Don’t forget to set

http.secure=true

Also, connectiontype will probably need a o be set to something > 3. See the httpsecuresocket docs for more info, but SSLv3 is probably not correct these days.

Greg, Paul, thank you for your input. I’m still having intermittent success.

I’ve created a test project on my Mac, with an HTMLviewer in a window. Upon attempting to connect the webpage loads fine. Since MacOS X uses webkit my username and password were saved in my keychain and used from there. When I deleted the keychain entry, a dialog box appears similar to what would appear in Safari, allowing me to enter my credentials successfully.

Meanwhile, I’ve set a breakpoint in the HTTPSecureSocket.AuthenticationRequired event handler which is loaded up with my credentials which does not fire on connection attempt.

This gets worse. Untimately I need it to work on Windows 7. The same project with no modifications fails with an ‘AuthenticationRequired’ error in Windows 7 on Parallels inside the HTMLviewer.

Any ideas? Should I set the renderer to something later e.g. >IE7? Would this be a HTTP 1.1 issue?

Cheers
Grant

I don’t know. HTTPSecureSocket.AuthenticationRequired works with digest authentication. Perhaps your web page is not using that?

Is there another way to achieve the desired results, possibly with internet headers?

Cheers
Grant

Try this before the Get: http.SetRequestHeader(“Authorization”,"Basic " + EncodeBase64(“username:password”))

Thanks Ashot. Still the same result.

Cheers
Grant

A question the authentication is in the webpage, or via a dialog asking you to authenticate?

I would suggest you use a network sniffing tool (Fiddler, Chrome Network Tools, Firefox Firebug), login via your browser, and then send the same HTTP requests via sockets(same headers, grabbing the cooking if needed, etc)

Ashot, no authentication dialog appears, just the error page. I have a network sniffing tool. I’ll give that a go to see what it turns up.

Cheers
Grant

Fwiw, it’s also possible that the site requires a valid user-agent.

BTW - There’s no way for you to know what the criteria is, but if I were them, if make it so you can’t do what you’re attempting anyway. Your program probably won’t hurt the site, but it’d be easy to create one that could.