VB automatically logs in the network site detailed (3): Internet Explorer object

zhaozj2021-02-16  48

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 use the login 9CBS as an example, give the actual code, you can replace the site you registered according to the parameters provided in the previous article:

Building a new project, "Reference" Internet Explorer object in the project, click "Browse", find ShDocvw.dll under the system folder (this file is IE comes with it), add Command1 in Form1, the following is the code -

DIM G_OIE AS INTERNETEXPLORERERERER

Private submmand1_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 (byteaRray () 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 run. The advantage of this method is obvious, you can transform the previous code according to this method.)

The PackBytes function converts the data out of POST into 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 SHDOCVW.DLL "library", 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.

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

New Post(0)