krunal1986 0 Junior Poster in Training

hi all,

i am not able to redirect/login to my owa page. when i run my code below commandd windoe comes and disappears nothing happens.

please seemy code below:

Sub main()

    Dim strServerName As String = "12.345.56.789" ' my owa ip
    Dim strPassword As String = "password" 'my password
    Dim strUserName As String = "username" ' my username

    ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf CertificateValidationCallBack)
    Dim strURL As String = "https://" & strServerName & "/exchange/"
    ''Dim strURL As String = "https://" & strServerName & "/owa/"
    Dim Response As System.Net.HttpWebResponse
    Dim RequestStream As System.IO.Stream
    Dim ResponseStream As System.IO.Stream

    Dim WebReq As HttpWebRequest = CType(System.Net.WebRequest.Create(strURL), System.Net.HttpWebRequest)
    WebReq.Credentials = New System.Net.NetworkCredential(strUserName, strPassword)
        WebReq.Method = "POST"
        WebReq.ContentType = "text/xml"
        WebReq.KeepAlive = True
        WebReq.AllowAutoRedirect = False

        Dim AuthUrl As System.Uri

        AuthUrl = New System.Uri("https://" + strServerName + "/exchweb/bin/auth/owaauth.dll")
        cookieJar = New CookieContainer

        WebReq.CookieContainer = cookieJar

        Dim strPostFields As String = "destination=https%3A%2F%2F" & strServerName & "%2Fowa%2F"
        Dim PostData() As Byte = System.Text.Encoding.ASCII.GetBytes(strPostFields)

        ' Set the content length.
        WebReq.ContentLength = PostData.Length
        Dim tmpStream As Stream
            ' Create a request stream. Write the post data to the stream.
            tmpStream = WebReq.GetRequestStream()
            tmpStream.Write(PostData, 0, PostData.Length)

        Catch ex As Exception
        End Try

        ' Get the response from the request.
        Dim WebResp As HttpWebResponse = WebReq.GetResponse()

        'WebReq.Timeout = 30000
        'ResponseStream = WebReq.GetRequestStream()
        'Response1 = WebReq.GetResponse()
    Catch ex As Exception
    End Try

End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.