HTTP wrappers are files that contain functions and procedures used to manage HTTP requests and responds, commonly used in the information exchange on the web (speaking of the HTTP protocol). But the question is: How to make my executable file (coded in VB.net in this case) exchange informations with a web server?
An immediate answer is the use of a web browser control, but this solution would awfully slow down my program. Hence the utility of HTTP wrappers!
Those wrappers contain two main functions that you will use to send to or retrieve from a web server: the GET function and the POST function.
As you may know, when you surf a web page using the HTTP protocol by the mean of a web browser, your web browser implicitly uses those two functions (ex: If you want to display a thread on LG, your browser sends a request to the server using the GET function. On the other hand, if you would like to login to your LG account, your browser sends your informations to the server using the POST function and therefore posting your informations in a special format -sometimes using hash functions to encrypt some 'private' informations such as passwords-). But what I want is that my executable does the same exact task without resorting to the use of a browser...
Part I: the GET and POST functions
To understand practically what happens, you will need Firebug, an addon -mainly available for Firefox users- that provides informations about POSTed or GOTten data from a webpage:
● To login to your LG account, you should POST your username and password, which is presented by Firebug as the following:
The vb_login_md5password variable necessary for the POST string contains your password hashed using the MD5 hash function.
● When you click on a thread's adress on LG, you GET the informations required to make the page load from the server (be they text, animation ...). All the pages components are displayed on Firebug, each with its URL preceded by the GET part:
For further informations about Firebug's features, here is a video.
PART II: Using the HTTP wrapper under VB.net
I will be using TEMPTii's HTTP Wrapper, available here.
In a new windows application project, go to Project -> Add an existing element ... or just press Ctrl+D; You will then be invited to add the wrapper.vb file located in the download. To use it in your form, declare it as a new public wrapper in the code tab:
Let's use this wrapper to GET LG index 's source code:Code:Public Class Form1 Public Something As New Wrapper End Class
Let's use this wrapper to login to an LG's account:Code:Function GetIndexPage() As String Return Something.GetWrapper("http://forum.logicalgamers.com/forum.php") End Function
The PostString variable is the string we've previously retrieved from Firebug, and the md5password string is the password hashed using the MD5 hash function.Code:Function LGlogin(ByRef username As String, ByRef md5password As String) As Boolean Dim PostString As String = "vb_login_username=" & username & "&vb_login_password=&vb_login_password_hint=Password&x=0&y=0&s=&securitytoken=guest&do=login&vb_login_md5password=" & md5password & "&vb_login_md5password_utf=" & md5password If Something.PostWrapper("http://forum.logicalgamers.com/login.php?do=login", PostString).IndexOf("Thank you for logging in") >= 0 Then Return True MessageBox.Show("Logged in.") Else Return False MessageBox.Show("Not logged in.") End If End Function
Notice that the PostWrapper function's type is string, in fact it contains the source code of the web page generated after having POSTed informations to the web server.
More functions can be available in an HTTPwrapper, such as getting a string between two specified strings from a known web page's source, ect.
It is practically all I know about the subject. I hope someone will get a use out of it, some day ... :smile: (And sorry for the french screenshots)
Results 1 to 3 of 3
- 15 Jul. 2011 04:36pm #1
VB.net's HTTPwrappers thoroughly explained
Last edited by ~Shieru No Tamashi~; 15 Jul. 2011 at 08:35pm.
- 16 Jul. 2011 01:59am #2
Very nice guide! One of the best I've seen in a long time.
- 16 Jul. 2011 09:04am #3
Thank you for your continuous support Arti <3 .