??
?
VB Automatically log in to the network site detailed (1): Get the parameter name ????
The automatic login site has a key place to be the correct or not of the parameter name, because the parameter names received by each web server are not the same, if the parameter name is incorrect, it will be misunderstood Therefore, it is recommended to recommend a very useful tool "Visual Sniffer": it can intercept the TCP / IP / UDP / ICMP and other data packets transmitted through the network, and use this tool to easily get the relevant parameters sent to the server.
Take the 9CBS as an example. Now let's open "http://www.9cbs.net/member/mme/login.asp "9cbs" http://www.9cbs login page, enter the account number, do not log in, run the Visual Sniffer, point Let's "start intercept" this button, then return to the landing page, click "Login", wait a moment, after login success, click "Stop Interception" on Visual Sniffer, now you can find some IE to send some what. (It is recommended to turn off excess IE before doing these, because if other IE windows are also sending data, you will be unnecessary interference in Visual Sniffer.)
Note that there are many " " numbers on the left side of Visual Sniffer, which is the data that is intercepted, launched them one by one, then check the data on the right, if the first line does not have "post" such a character, Then quickly change a " ", which is the fastest way to send data to the 9CBS server (our login is "post" request, if you see "get", it is certainly not). Please see the actual picture:
? First add the file header to the header, there are a few not very important, so there is not much to say:
"Accept:" indicates the file format that can be received.
"Referr:" indicates the file address pointed to.
"Accept_language:" indicates the language accepted.
"Host:" indicates the host name.
The purple line portion in the figure is in the picture, which is the address sent by the POST. The red line is either all the servers need to receive parameters, four equal numbers indicate that the total four parameters are "&" connects. By the way, the cookie: aspsession you see ... long this is a session, which is sent by the server when IE and the server requests the connection, and now returned to it. You can check out elsewhere in Visual Sniffer, when it's getting. Due to the program, we use the control, do not need to consider the problem of cookie and session, because VB's INET, WebBrowser is packaged very well, the key is how to use it correctly.
"Login_Name", "password" is the most important parameter name received by 9CBS during landing; in addition, there is a "cookietime" to tell the local cookie's effective time, these three must be sent when landing 9CBS parameter. The account and password are the parameters required for the general landing site, but some servers receive more than three parameters. In addition to the account and password, we can use other parameters as a third parameter, and the "&" connection is used. In addition, it is more important to "Content-Type: Application / X-WWW-FORM-URLENCODED", tell the server to decode the way, if there is less, you can't do anything.
When logging in to other forums, email, and communities can get all important information about POST through Visual Sniffer, and this is also a method I recommend to everyone, especially when some parameters are not so easy to analyze from the HTML source file. Not only that, you can also use this method to intercept your own procedure, because it is also the HTTP protocol, Visual Sniffer is also able to intercept. This way you can compare the procedure and the IE is nothing to do with the IE to achieve the purpose of the error. ?
?? VB Automatically logs in the network site detailed (2): INET control with the webbrowser control, use ????
?
URL account password other parameter SOHU mailbox http://login.sohu.com/chkpwd.php username password?
Netease Pass http://reg4.163.com/checkuser.jsp UserName Password?
9CBS Pass http://www.9cbs.net/member/logon.asp login_name password cookietime = 0 & x = 42 & y = 10 The parameters in the table are obtained in the previously described method, will be used in the program. First, the webbrowser is also directly POST data to the web server, I will give the code in the fourth part. Here first look at the effect of inet and webbrowser mutual cooperation.
Create a new project, tick "Microsoft Internet Transfer Controls 6.0", "Microsoft Internet Controls", add INET1, WebBrowser1, Text1, Text2, and Combo1 in the form, you can take WebBrowser1 appropriately, position control position Arrange (you can refer to the picture after running), below is the code: ??? DIM URL1 (2) AS STRING: DIM URL2 (2) AS STRING ??? DIM C1 (2) AS STRING: DIM C2 (2) AS STRING: DIM C3 (2) AS STRING PRIVATE SUB FORM_LOAD () ?????? Text1.text = "" ??? Text2.text = "" ??? Text2.passwordChar = "*" ?? combo1 .Additem "sohu mailbox", 0 ??? combo1.additem "Netease Pass", 1 ??? Combo1.Additem "9CBS Pass", 2 ??? combo1.additem "Please select a landing", 3 ??? combo1 .Text = Combo1.List (3) ??? url1 (0) = "http://login.sohu.com/chkpwd.php": URL2 (0) = "http://www34.mail.sohu.com / control / entry "??? URL1 (1) =" http://reg4.163.com/checkuser.jsp ": URL2 (1) =" http://reg4.163.com/main.jsp? " ??? URL1 (2) = "http://www.9cbs.net/member/logon.asp": URL2 (2) = "http://www.9cbs.net/member/passport.asp" ?? ? C1 (0) = "username": c2 (0) = "password": c3 (0) = "" ??? C1 (1) = "username": C2 (1) = "password": c3 (1 ) = "" "" C1 (2) = "login_name": C2 (2) = "PA SSWORD ": C3 (2) =" cookietime = 0 & x = 42 & y = 10 "End Sub Private Sub Form_Resize () if Me.WindowState <> 1 THEN ??? WebBrowser1.Width = Me.Width - 120 ??? Webbrowser1.height = me.height - 800 end if End sub private sub text2_keyup (Keycode As INTEGER, SHIFT AS INTEGER) ??? if keycode <> 13 THEN EXIT SUB ??? if Combo1.listIndex = 3 "Please select a landing"
: EXIT SUB ??? if text1.text = "" THEN MSGBOX "Please enter the username": EXIT SUB ??? if text2.text = "" THEN MSGBOX "Please enter the password": EXIT SUB ??? Dim StrformData As String ??? StrformData = C1 (Combo1.ListIndex) "=" Text1.Text "&" C2 (Combo1.ListIndex) "=" Text2.Text "&" C3 (Combo1.ListIndex) ??? inet1.executex, "post", strformdata, "content-type: application / x-www-form-urlencoded" ??? do until inet1.stillexecuting = false 'Here you block the previous inet1 Make sure that the page will be taken after the login is successful, you can cancel this DO. ??????? doevents ??? loop ??? if Combo1.ListIndex = 1 THEN ??????? Webbrowser1.naviGate URL2 (Combo1.ListIndex) "=" Text1.text ??? Else ??????? WebBBROWSER1.NAVIGATE URL2 (Combo1.ListIndex) ??? End if End Sub?
You can pick a site that you have already registered to see the effect. It can be seen that after the success is successful, Inet and WebBrowser can keep the same session dialogue! But when we clicked on a connection on the webbrowser displayed, the request could not succeed (please try it yourself, and arbitrarily click on a connection to the successful site, the population will be a " You don't log in "page). why? Because we now click on the connection or use IE (operating system default browser) to open, and the IE request page is using the server new session, this new session is the session you used in WebBrowser. The identity ID is different, at least the server thinks so, it is another user without landing. So saying the SESSION's role is not for the entire client, and it can be well understood by the actual code. (You can use this, use code to implement more than two users on one computer, and even seamlessly speak on the same topic.) So let's let the page continue to stop in WebBrowser. Because it is clear, since WebBrowser and inet can keep the same session dialogue, WebBrowser and WebBrowser are naturally natural! To add the code is very simple - Private Sub WebBrowser1_NewWindow2 (ppDisp As Object, Cancel As Boolean) ??? Dim frm2 As New Form2 ??? frm2.WebBrowser1.RegisterAsBrowser = True ??? Set ppDisp = frm2.WebBrowser1.Object? ?? frm2.show end Sub then adds a FORM2 in the project, put a webbrowser1, adjust the location, Form2's code window Add: private sufm_load () webbrowser1.silent = TRUE END SUB?
Private Sub Form_Resize () if me.windowstate <> 1 THEN ??? WebBrowser1.left = 10 ??? WebBrowser1.Width = Me.Width - 120 ??? WebBBROWSER1.HEIGHT = Me.HEight - 600 End If End Sub Private Sub webbrowser1_newwindow2 (PPDISP As Object, Cancel As Boolean) 'Here, in order to avoid things that happen in Form1. ??? DIM FRM2 AS New Form2 ??? frm2.webbrowser1.registerasBrowser = true ??? set ppdisp = frm2.webbrowser1.object ??? frm2.show end subjected to login request, webbrowser browsing the actual page, is indeed Very good ideas, there should be no problem in the case where the landing site is less teaching. But this will make things more complicated. In addition to the unusual POST address (URL1), account parameters (C1), password parameters (C2), other parameters (C3), there must be a page address parameter (URL2) for webbrowser request browsing. Although only a parameter, it has added a lot of trouble (such as the request page of the NetEase mailbox, which is automatically generated according to the user's account name, not fixed). Only the fourth parameter can only be avoided using WebBrowser directly POST data. But the interface and function of the browser are a more troublesome problem (unless you are not too trouble, you will write one). ? VB automatically logs in the network site detailed (3): Internet Explorer object ????
Using the Internet Explorer object allows the POST request to be generated in IE, so that the procedure is away from the work of the beautification interface. The program can even hide or exit, eliminating the troubles brought by WebBrowser, and of course the fourth parameter is not required. Below us, we still have an example of logging in to 9CBS, give the actual code, you can replace the site you registered in accordance with the parameters provided in the previous article: Building a new project, "Reference" Internet Explorer object in the project, point "Browse", Locate ShDocvw.dll under the system folder (this file is IE itself), add Command1 in Form1, the following is the code -?
??? DIM G_OIE AS INTERNETEXPLORER PRIVATE SUB Command1_Click () ??? DIM VPOST AS VARIANT ??? DIM VHEADERS AS VARIANT?
??? set g_oie = new internetExplorer ??? g_oie.visible = true ??? ??? redim Abyte (0) as byte ??? cpostdata = "login_name = account & password = password & cookietime = 0" ??? PackBytes Abyte (), cpostdata ??? ??? vpost = Abyte ??? vheaders = "content-type: application / x-www-form-urlencoded" chr (10) chr (13) ??? ??? g_oie .Navigate "http://www.9cbs.net/member/logon.asp",,, vpost, vheaders ??? End sub private sub packbytes (byterray () as Byte, ByVal PostData As String ??? inewbytes = Len (PostData) - 1 ??? if inewbytes <0 THEN EXIT SUB ??? Redim ByTearray (inewbytes) ??? for i = 0 to inewbytes ?????? ch = MID (PostData, i 1, 1 ) ?????? if ch = space (1) THEN ????????? CH = " " ?????? end if ?????? ByTearray (i) = ASC ( CH) ??? Next End Sub (please enter your own account and password trial operation. The advantage of this method is obvious, you can transform the previous code in this way.) The PackBytes function transforms the data from POST to An ASCII array, and the value of Vheaders must end with " chr (10) chr (13)". • There is no good explanation of the code, and now I have entered the "library" that I have entered the SHDOCvw.dll, and the webbrowser and Internet Explorer, which are mentioned earlier are "classes" included in this library. You can open the object browser to see the relationship between them.
?
VB Automatically login network site detailed (4): Send a POST request in WebBrowser ???? The content of this part should also be placed in the second chapter, on the one hand, in order to be eye-catching, on the other hand, this method is actually with Internet Explorer Objects have great links and similarity, so they will be introduced after the Internet Explorer object. ?
Now what we are going to use is the "navigate" method of WebBrowser, whose function prototype is as follows: Sub Navigate (URL AS String, [Flags], [TargetFramename], [POSTDATA], [HEADERS])?
Everyone may wish to compare it with the "navigate" method of the Internet Explorer object in Chapter 3, exactly the same interface! ! Create a new project, check "Microsoft Internet Controls", add a webbrowser1, a command1 on the form, you can take WebBrowser1 appropriately, add the following code to Form1: ??????prate SUB Command1_click ()? ???? redim Abyte (0) as byte 'array = "login_name = account & password = password & cookietime = 0 & x = 42 & y = 10" ????? PackBytes Abyte ), cpostdata ????? DIM VPOST AS VARIANT ????? vpost = Abyte 'Assign To A Variant ????? DIM VHEADERS AS VARIANT ????? vheaders = "Content-Type: Application / x-www-form-urlencoded " chr (10) chr (13) ????? Webbrowser1.navigate" http://www.9cbs.net/member/logon.asp ",, VPost, Vheaders ????? End Sub ????? private sub packbytes (ByVal PostData As String) ???? inewbytes = len (postdata) - 1 ?? 'Get Rid of the Null Termination? ???? if inewbytes <0 THEN ?????? EXIT SUB ????? end if ????? redim ByTearray (inewbytes) ????? for i = 0 to inewbytes ????? CH = MID (PostData, i 1, 1) ?????? if ch = space (1) Then ???????? CH = " " ?????? endiff? ????? debug.print CH, ASC (CH) ?????? ByteaRray (i) = ASC (CH) ????? next ??? End Sub (refer to the code in Chapter 3. Through the introduction of these four articles, I think readers must not only have a deeper understanding of VB login web server, and at the same time understand the HTTP protocol, cookie, session has also deepened! Full text! ! ! Note: This series of articles, please do not use commercial purposes, please contact me in advance, please contact me in advance.