PDA

View Full Version : xmlHttp get requst - cannot get past login



CodeNinja
10-08-2012, 01:52 PM
Hi Gang,
I have been working on a report collector that will download reports from the web. The program works, but takes a lot of time if I have a lot of reports to download. In an effort to make the code more efficient, I am looking to move some of the code from using an ie object to a get request using the xmlHTTP object.

The application is attached for your enjoyment, although I have not attached the udl file for security purposes.

My problem though, is that I cannot seem to get the xmlHTTP object to get past the password. When I run the following code, it returns the HTML of the page you would get if you did not enter the correct password.

I have tried putting the user ID and Password in the same line as the open statement:
.Open "get", sURL, False, "****", "****"
... but that gives me the same results as the code below, just returning the page as if I put in a wrong password or none at all.

Help would be greatly appreciated in figuring out how to get past the password stage and into html of the site.




Sub testGetHTML()
Dim sURL As String
Dim xh As XMLHttp
Dim sPostData As String

Set xh = New MSXML2.XMLHttp
sPostData = "Username=*****&Password=*****"
sURL = "http://hyattselectreports.lraqa.com//index.php?page=&propid=33809"

With xh
.Open "get", sURL, False

.send (sPostData)

Debug.Print .responseText
End With

End Sub


Thanks,

CodeNinja

snb
10-08-2012, 02:27 PM
Did you try ?


Sub testGetHTML_snb()
' reference microsoft Winhttp services, verion 5.1

With New WinHttpRequest
.Open "get", "http://hyattselectreports.lraqa.com//index.php?page=&propid=33809"
.SetCredentials "username", "passwrd"
.send

Debug.Print .responseText
End With

End Sub

CodeNinja
10-09-2012, 08:03 AM
snb,
Thanks for the reply... I tried the httprequest as you suggested, and got the same problem... it is not getting past the login screen ... Am I using the wrong flag?

Sub testGetHTML_snb()
' reference microsoft Winhttp services, verion 5.1

With New WinHttpRequest
.Open "get", "http://hyattselectreports.lraqa.com//index.php?page=&propid=33809"
.SetCredentials UserName:="*****", Password:="*****", flags:=HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
.send

Debug.Print .responseText
End With

End Sub

Kenneth Hobs
10-09-2012, 12:00 PM
Try waiting for a response before putting the response text into the immediate window.
.WaitForResponse

CodeNinja
10-09-2012, 01:56 PM
Tried the following, got the same result (returning html of page where login is incorrect). Obviously, I have obscured the login for security purposes, but I am 100% sure I am using a correct login.

Is this what you were thinking Kenneth? Do you have any other ideas?


Sub testGetHTML_snb()
' reference microsoft Winhttp services, verion 5.1

With New WinHttpRequest
.Open "get", "http://hyattselectreports.lraqa.com//index.php?page=&propid=33809"
.SetCredentials UserName:="****", Password:="*****", flags:=HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
.send
.WaitForResponse

Debug.Print .responseText
End With

End Sub


Thanks so much,

Code Ninja