exception using HTTPWebRequest with SSL
- From: "BillE" <belgie@xxxxxxxxxxx>
- Date: Thu, 22 Feb 2007 18:33:20 -0500
VS2005 VB.net
I'm using the HTTPWebRequest class to connect to a web site with SSL. I
first manually connected to the site and installed the certificate on my
computer, and then use the X509Certificate class to add the certificate to
the HTTPWebRequest, but I continue to get the exception:
"The underlying connection was closed: Could not establish trust
relationship for the SSL/TLS secure channel."
Inner Exception:
"The remote certificate is invalid according to the validation
procedure."
KB895971 says the certificate should be installed in the LOCAL_MACHINE
registry hive, but it got installed in the CURRENT_USER registry hive.
Is this the problem?
How do I install the certificate in the LOCAL_MACHINE hive instead of the
CURRENT_USER hive?
Thanks
Bill
----------------------------------------------------------------------------------------------
I have tested the code below on a non-SSL site and it works fine.
Sub SendRequest()
Dim sHTTPResponse As String = ""
Dim url As String = "https://www.abc.com/login.asp"
Dim myHttpWebRequest As HttpWebRequest
Dim myHttpWebResponse As HttpWebResponse
myHttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
myHttpWebRequest.Method = "POST"
Dim postData As String = "username" + ChrW(61) + "uname"
postData += "&password" + ChrW(61) + "pwd"
Dim encoding As New ASCIIEncoding()
Dim byte1 As Byte() = encoding.GetBytes(postData)
' Set the content type of the data being posted.
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"
' Set the content length of the string being posted.
myHttpWebRequest.ContentLength = byte1.Length
Dim cert As X509Certificate =
X509Certificate.CreateFromCertFile("C:\Documents and Settings\xxx\My
Documents\Certificate.cer")
myHttpWebRequest.ClientCertificates.Add(cert)
Dim newStream As Stream = myHttpWebRequest.GetRequestStream()
newStream.Write(byte1, 0, byte1.Length)
' Sends the request and waits for a response.
myHttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
Dim sr As New StreamReader(myHttpWebResponse.GetResponseStream)
Dim res As String = sr.ReadToEnd
Me.TextBox1.Text = res
End Sub
.
- Prev by Date: Re: make checkBox ReadOnly wihtout Enabled = False? VB2005
- Next by Date: Re: make checkBox ReadOnly wihtout Enabled = False? VB2005
- Previous by thread: Re: make checkBox ReadOnly wihtout Enabled = False? VB2005
- Next by thread: Proper Design
- Index(es):
Relevant Pages
|