1

i am looking into this issue since days but i am not able to find a solution. I want to use WinHttp Authentication via VBA to Login to our Redmine to get the current issues.csv file for my Excel spreadsheets. I already found this useful question on Stackoverflow and adapted the Code(Not understanding why WinHTTP does NOT authenticate certain HTTPS resource) , but its not working with that as well. I always get the LoginPage html Content as ResponseBody.

This is the specific part of the Code:

Set RegX_AuthToken = CreateObject("VBScript.RegExp")
'Below Pattern w/o double-quotes encoded:(?:Input name="authenticity_token" value=")(.*)(?:")
RegX_AuthToken.Pattern = "(?:input type=" & Chr(34) & "hidden" & Chr(34) & " name=" & Chr(34) & "authenticity_token" & Chr(34) & " value=" & Chr(34) & ")(.*)(?:" & Chr(34) & ")"
RegX_AuthToken.IgnoreCase = True
RegX_AuthToken.Global = True
RegX_AuthToken.MultiLine = True

TargetUrl = myURL

Set httpreq = CreateObject("WinHttp.WinHttpRequest.5.1")
httpreq.Open "GET", TargetUrl, False
httpreq.Send

Set token_Match = RegX_AuthToken.Execute(httpreq.ResponseText)

Authtoken = token_Match(0).SubMatches(0)

PostData = "authenticity_token=" & Authtoken & "&back_url=https://tickets.gbo-datacomp.de/" & "&username=" & "XXX" & "&password=" & "XXX" & "&login=Login »"

httpreq.Open "POST", TargetUrl, False
httpreq.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
httpreq.Send (PostData)

TargetUrl = myUrl&"issues.csv"
httpreq.Open "GET", TargetUrl, False
httpreq.Send

oResp = httpreq.ResponseBody

Would be great if somebody could Point me to my mistake.

Thanks in advance for your suggestions!

ChristianR
  • 11
  • 1
  • Try to retrieve and send cookies, and URL-encode concatenated variables within `PostData`. Is `Login »` part correct there? – omegastripes Jan 11 '18 at 12:36

1 Answers1

0

I had the same problem, at my company my certified is up to date, so you have to ignore the certified erros by using:

HTTPReq.Option(4) = &H3300

It works for me!