Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use vb 6 to login to a web page 2

Status
Not open for further replies.

bigbiceps

IS-IT--Management
Sep 29, 2005
6
GB
Using a vb program i used to download some files from a web site which is no longer available. The new web site requires usernam and password..how can i automatically supply these to get to the files?
Any help on links etc most appreciated
 
Are there any text fields to write the UserName and PassWord
-or-
It is like ftp, where a dialog appears and your write them there where also you can check "Anonymous Login" and login if allowed.

?
 
There are text fields to write the username and password
 
Add a browser control (name=AxBrowser1)

--Goto the web page, view the source and find the names or IDs of the username field and the password's.
--Also find the ID of the button that does the login.

AxBrowser1.document.getElementById("UserNameFieldID").Value = "..."
AxBrowser1.document.getElementById("PassWordFieldID").Value = "..."
AxBrowser1.document.getElementById("LoginORsubmitButtonID").Click()

 
Fendal: in your case the site is using "basic authentication" to control login. This is a protocol that is handled between the web server and the browser, and you have no real control over it. There is a solution however. Just add userid:password@ in front of the domain name or ip address. For example:

[ignore][/ignore]

Note that this will NOT work in most browsers now (for security reasons) but it should still work with the VB browser controls (it does for me).

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
If it doesn't work, come back and let us know. I ran into some weird things trying to make that work with variables. I ended up with this code:
Code:
  Set daDoc = frmBrowser.brwWebBrowser.Document
  'Don't know why, but the form, field, and control names MUST be enclosed in an extra set
  'of parens to force them to evaluate before the statement itself is evaluated.
  For X = 1 To UBound(FormFields, 2)
    daDoc.Forms((FormName)).elements((FormFields(1, X))).Value = FormFields(2, X)
  Next X
  daDoc.Forms((FormName)).elements((SubmitButton)).Click

FYI: the comments are actually part of the code in the program. That way I'll remember why the code looks the way it does next time I look at it (just like this time).

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
i tried the userid:password@ but it does not work on the site.. i'll look at the source for the id's...i was also trying sendkeys which does work but as the username textbox is not automatically selected i was trying to tab to it..however if the page does not display quickly then i end up putting the password in the wrong area..i will need some sort of wait..
thanks so far
 
userid:password@ hardly ever works under HTTP; it isn't an RFC requirement (it does normally work for FTP, though)
 
That doesn't work under HTTP from the browser anymore because it was used by unscrupulous persons as a way of obfuscating which url you were actually going to (there's some info on MSDN about it, but I forget where).

It DOES work with the webBrowser control in VB6 though - just like I showed above. There might be a server setting that can disable it too, but if so it hasn't been set on the server I use.

If you can't get it to work, you'll have to find the window that pops up asking for the id and password, and use SendKeys to send it the userid and password. Not the way I'd want to do it, since using SendKeys is problematic at best.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Sure, you'll be talking about
(which came about, amongst other reasons, after 'unscrupulous' people created a spoof Microsoft webpage and conned people into thinking it was real through the obfuscation technique)

I'll repeat, however, that the RFCs (see RFC1738, for example) make no requirement that this syntax work or be supported for HTTP.
 
I disagree with your reading of the RFC, but the fact remains the it frequently DOES work, except for the security patches issued to disable its use in web browsers.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Disagree if you wish. The fact remains that section 3.1 (which for some reason many people think describes a general syntax all of which is to be used by all the schemes) merely describes a common syntax from which the various schemes can be derived; i.e not all the schemes are required to support all the parts.

If you then read the rest of the RFC, only FTP and Telnet have the username:password syntax defined (and even there, they are optionsal)

Furthermore, later RFC's vaguely advise against the use of the syntax.

Here: since you're reading of the RFC differs from mine, have an opinion from someone else
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top