Capture Headers

I figured out (thanks to the EExperts) how to log into my router. Now, I want to catch the headers that initiate the HTTP authentication. THe point is that I want to catch the Basic Realm from the authentication header.
LVL 32
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

'ADD 1 command button and add the following to the form.

Option Explicit
Dim WinHttpReq As Object

Private Sub Form_Load()
    Set WinHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
End Sub

Private Sub Command1_Click()
    WinHttpReq.Open "GET", "http://username:password@", False
    'set username and password below as well
    WinHttpReq.SetCredentials "username", "password", HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
    Debug.Print WinHttpReq.Status & " " & WinHttpReq.StatusText
    Debug.Print WinHttpReq.GetAllResponseHeaders & "  " & WinHttpReq.ResponseText
    Set WinHttpReq = Nothing
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
If the late binding doesn't work...Then you need to add a reference to Microsoft WinHTTP.  However the latebinding should work.
DrDamnit, this is just in support of egl's answer.  I don't want points for this.

egl, that works for me.  But you will want to comment out the setcredentials line to force the server to return a 401 status, because the header he wants is only returned when authentication is required but not present.   Also, the httprequest object doesn't seem to take the username:password URL syntax, so you may as well get rid of it.  But it's a good job of showing how to use the httprequest object to login as well, that works quite nicely.  :)

PaulHews, Could be used to get the WAN IP as well. Although for personal use only.
The positions will be off though.

WanPos1 = InStr(router_body, "WAN:")
WanStr1 = Mid$(router_body, WanPos1, 310)
WanPos2 = InStr(WanStr1, "IP Address:")
WanStr2 = Mid$(WanStr1, WanPos2, 120)

Erase RemoveString
Dim strFix As String
RemoveString = Split("<->-&nbsp-td-font-verdana- /-size=-/ face=-/-tr-bgcolor=-;", "-")
For I = LBound(RemoveString) To UBound(RemoveString)
WanStr2 = Replace(WanStr2, RemoveString(I), "")
Next I

MsgBox Mid(WanStr2, 14, 21)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.