0

With reference to this question VBA XMLHTTP clear authentication? I am also trying to pass basic authentication in VBA. It works perfectly.

My only concern is login pop up which comes up whenever a wrong userid or password is sent in request. Is there a way to disable this and send a message box to user from VBA itself telling him about authentication failure?

Update

VBA code:

Dim objHTTP As New MSXML2.XMLHTTP60

With objHTTP

    .Open "GET", UrlUserService, False
    .setRequestHeader "Content-Type", "application/json"
    .setRequestHeader "Accept", "application/json"
    .setRequestHeader "Cache-Control", "no-cache"
    .setRequestHeader "Authorization", "Basic " + Base64Encode(userName + ":" + userPwd)
    .setRequestHeader "Pragma", "no-cache"
    .setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
    .send ""
    response = .Status

End With

Popup enter image description here

Community
  • 1
  • 1
user0404
  • 87
  • 1
  • 11
  • Could you provide a [mcve] please? To me it is unclear how this popup looks like. – Pᴇʜ Sep 08 '17 at 12:10
  • Done, not able to upload image so added URL from MSDN, its basically windows security pop-up – user0404 Sep 08 '17 at 12:53
  • You can test if `Application.DisplayAlerts = False` then write your code and `Application.DisplayAlerts = True` at the end suppresses this alert. – Pᴇʜ Sep 08 '17 at 12:56
  • Nope, that didn't worked. – user0404 Sep 08 '17 at 13:11
  • 1
    Use `Dim objHTTP As New MSXML2.ServerXMLHTTP60` to avoid the popup, then you can check `.Status`. If 401 authentication has failed. Don't ask me about the diff to `XMLHTTP60`, I have not found a good explanation yet, but if I do and this works for you I will post this as answer. – BitAccesser Sep 09 '17 at 07:29
  • 1
    @BitAccesser Yes, you are right. Using `ServerXMLHTTP60` didn't show any popup. Also if I use `.Open "GET", UrlUserService, False, userName,userPwd` pop-up won't come – user0404 Sep 11 '17 at 10:12

1 Answers1

2

Use Msxml2.XMLHTTP.6.0 protocol and pass the credentials as part of request

.Open "GET", pUrl, false, "pUsername", "pPassword"

Indrajit
  • 21
  • 3