VB Automatic Login Network Site Detailed (2): INET Controls Work with WebBrowser Controls

zhaozj2021-02-16  41

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, and 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 flow_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) = "Password": C3 (2) = "Cookietime = 0 & x = 42 & y = 10"

End Sub

PRIVATE SUB FORM_RESIZE ()

If me.windowstate <> 1 lifebbrowser1.left = 10

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 Then Msgbox "Please select a landing": EXIT SUB

If Text1.Text = "" THEN MSGBOX "Please enter your username": EXIT SUB

If text2.text = "" "THEN MSGBOX" Please enter your password ": EXIT SUB

DIM STRFORMDATA AS STRING

StrformData = C1 (Combo1.ListIndex) "=" TEXT1.TEXT "&" C2 (Combo1.ListIndex) "=" Text2.Text "&" C3 (Combo1.ListIndex)

INET1.EXECUTE URL1 (Combo1.ListIndex), "Post", StrformData, "Content-Type: Application / X-WWW-FORM-URLENCODED"

DO Until inet1.stillexecuting = false 'Here you block the previous INET1, make sure you will take the page after the login is successful, you can cancel this DO.

Doevents

Loop

IF combo1.listindex = 1 THEN

WebBrowser1.naviGate URL2 (Combo1.ListIndex) C1 (Combo1.ListIndex) "=" Text1.Text

Else

WebBrowser1.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, using 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 display in WebBrowser. Because it is clear, since WebBrowser and inet can keep the same session dialogue, WebBrowser and WebBrowser are naturally natural! The code to be added is 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 add an FORM2 in the project, put a webbrowser1, adjust the location, and the following code is added to the Form2:

Private sub flow_load ()

Webbrowser1.silent = true

End Sub

PRIVATE SUB FORM_RESIZE ()

IF me.windowstate <> 1 THEN

Webbrowser1.left = 10

WebBrowser1.width = me.width - 120

Webbrowser1.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 Sub

Use inet to send login requests, webbrowser browsing the actual page, is indeed a very good idea, there should be no problem in the case where the landing site is relatively less. 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).

转载请注明原文地址:https://www.9cbs.com/read-26854.html

New Post(0)