Reputation: 1202
I have a macro which is triggering a GET call to the portal. Below is the URL structure:
https://{P_URL_PORT}/ibm/console/status?text=true&type=cluster&name={P_CELL}&time={tStamp}
Here is my macro.
Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
WinHttpReq.Open "GET", strURL, False, userNTID, userPassword
WinHttpReq.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
WinHttpReq.Send
result1 = WinHttpReq.responseText
But I am not getting expected response. It is displaying the Login Screen response. I have tried adding POST method where it will send the Login URL, Username, and password. But still the GET call is not retrieving the actual response.
Upvotes: 1
Views: 4265
Reputation: 712
The open function for WinHttpRequest does not take username and password as parameters. If you are able to automatically login to the site in Internet Explorer then you may use those settings by SetAutoLogonPolicy()
Caveat: Automatic login would imply not due to cookie but by the proxy settings. At times you can auto-login to a site because browser has remembered your last login.
To be sure:- Close all browser windows. Open Private Window. If you auto-login now it means it is set in Internet Options and SetAutoLogonPolicy() should work.
Dim URL As String
URL = "" 'provide URL
Dim HDoc As HTMLDocument
Dim whr As New WinHttpRequest
whr.Open "GET", URL, False
whr.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
whr.SetAutoLogonPolicy AutoLogonPolicy_Always
whr.Send
In case you need to login you supply the credentials, then use SetCredentials(). A good example of such request can be found here
Upvotes: 1