Private Function DoExchangeFBA() As CookieCollection Dim server As String = "https://mail.myechangeserver.co.za" Dim uri = server & "/exchweb/bin/auth/owaauth.dll" Dim request = DirectCast(HttpWebRequest.Create(uri), HttpWebRequest) request.Method = "POST" request.CookieContainer = New CookieContainer() request.ContentType = "application/x-www-form-urlencoded" request.AllowAutoRedirect = False request.ServicePoint.Expect100Continue = False Dim username As String = txtEmailAddress.Text Dim password As String = txtPassword.Text server = HttpUtility.UrlEncode(server) username = HttpUtility.UrlEncode(username) password = HttpUtility.UrlEncode(password) Dim bodyString = "destination={0}&flags=0&username={1}" bodyString += "&password={2}&SubmitCreds=Log+On&" bodyString += "forcedownlevel=0&trusted=0" bodyString = String.Format(bodyString, server, username, password) Dim body = Encoding.ASCII.GetBytes(bodyString) request.ContentLength = body.Length ServicePointManager.Expect100Continue = False Dim stream = request.GetRequestStream() stream.Write(body, 0, body.Length) stream.Close() Dim response = DirectCast(request.GetResponse(), HttpWebResponse) 'Here is where the cookies.count always returns 2 If response.Cookies.Count < 2 Then Throw New AuthenticationException("Failed to login to OWA!") End If Return response.Cookies End Function
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)