Results 1 to 2 of 2

Thread: [RESOLVED] need help in The underlying connection was closed: Could not establish trust relation

  1. #1

    Thread Starter
    Addicted Member acidsnake's Avatar
    Join Date
    Feb 2008
    Posts
    157

    Resolved [RESOLVED] need help in The underlying connection was closed: Could not establish trust relation

    Code:
    Imports System.Net
    Imports System.IO
    Imports System.Text
    Imports System.Security.Cryptography.X509Certificates
    Imports System.Net.Security
    
    Public Class Form1
        Dim logincookie As CookieContainer
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim postdata As String = "username=" & TextBox1.Text & "&password=" & TextBox2.Text & "&sub_form=Sign+In" & TextBox1.Text & "&password=" & TextBox2.Text & "&sub_form=Sign+In"
            Dim tempCookies As New CookieContainer
            Dim encoding As New UTF8Encoding
            Dim bytedata As Byte() = encoding.GetBytes(postdata)
    
            Dim postreq As HttpWebRequest = DirectCast(WebRequest.Create("https://122.52.209.250/login.do"), HttpWebRequest)
            postreq.Method = "POST"
            postreq.KeepAlive = True
            postreq.CookieContainer = tempCookies
            postreq.ContentType = "application/x-www-form-urlencoded"
            postreq.Referer = "https://122.52.209.250/login.do"
            postreq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16"
            postreq.ContentLength = bytedata.Length
    
    
            Dim postreqstream As Stream = postreq.GetRequestStream()
            postreqstream.Write(bytedata, 0, bytedata.Length)
            postreqstream.Close()
    
            Dim postresponse As HttpWebResponse
    
    
            postresponse = DirectCast(postreq.GetResponse(), HttpWebResponse)
            tempCookies.Add(postresponse.Cookies)
            logincookie = tempCookies
    
            Dim postreader As New StreamReader(postresponse.GetResponseStream())
    
            Dim page As String = postreader.ReadToEnd
    
            WebBrowser1.DocumentText = page
    
        End Sub
    
    
    
        Function CertificateValidationCallBack(ByVal sender As Object, _
            ByVal certificate As System.Security.Cryptography.X509Certificates.X509Certificate, _
            ByVal chain As X509Chain, _
            ByVal sslPolicyErrors As Security.SslPolicyErrors _
        ) As Boolean
    
            Return True
        End Function
    
        Private Sub MakeRequest()
    
            'Set the callback
            ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf CertificateValidationCallBack)
    
            'Make the request
    
        End Sub
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            'WebBrowser1.DocumentText = RichTextBox1.Text
    
    
    
        End Sub
    End Class

  2. #2

    Thread Starter
    Addicted Member acidsnake's Avatar
    Join Date
    Feb 2008
    Posts
    157

    Re: need help in The underlying connection was closed: Could not establish trust rela

    hi to all kindly check my syntax in passing a security certificate if it's right or wrong thanks in advance

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width