|
-
Jan 5th, 2004, 08:16 PM
#1
Thread Starter
Addicted Member
SSL Error
I keep getting the following error message when trying to make an SSL Connection via VB.NET's WebRequest:
The underlying connection was closed: Could not establish trust relationship with remote server.
VB Code:
Private Function SendXML(ByVal xml As String) As String
Dim aURL As String
aURL = "https://www.site.com:10027"
Dim wr As HttpWebRequest = Net.WebRequest.Create(aURL)
Dim cert As System.Security.Cryptography.X509Certificates.X509Certificate
cert = System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromSignedFile("C:\cert\ca.cer")
wr.ClientCertificates.Add(cert)
wr.ContentType = "text/xml"
wr.KeepAlive = False
wr.Method = "POST"
Dim sw As StreamWriter
Try
sw = New StreamWriter(wr.GetRequestStream())
sw.Flush()
sw.AutoFlush = True
Catch ex As Exception
Return False
End Try
Try
sw.Write(xml)
sw.Flush()
sw.Close()
Catch ex As Exception
Return False
End Try
wr.Timeout = 900000
Dim wres As HttpWebResponse = wr.GetResponse
Dim s As IO.Stream
s = wres.GetResponseStream
Dim sr As IO.StreamReader
sr = New IO.StreamReader(s)
Return sr.ReadToEnd
End Function
-Daryl
"Two More Rolls of Duct tape, and the world is mine!"
VB.NET Guru
-
May 16th, 2004, 05:05 PM
#2
yay gay
hmm I need to send some things (like on a submit form) and then download the output(just registering in a forum and then retrieving the "you are being logged in blablabla" but in a site which is https(SSL).
I am facing the same trouble, anyway to go over it?
\m/  \m/
-
May 17th, 2004, 11:27 AM
#3
Thread Starter
Addicted Member
Here is how I got it to work, note that first line:
Code:
ServicePointManager.CertificatePolicy = New MyPolicy
Dim sURL As String = "https://www.site.com:10027"
Dim uUri As Uri = New Uri(sURL)
Dim wr As HttpWebRequest = Net.WebRequest.Create(uUri)
Dim cert As System.Security.Cryptography.X509Certificates.X509Certificate
cert = System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromCertFile("C:\Cert\ca.cer")
wr.ClientCertificates.Add(cert)
wr.ContentType = "text/xml"
wr.KeepAlive = False
wr.Method = "POST"
Dim sw As StreamWriter
Try
sw = New StreamWriter(wr.GetRequestStream())
sw.Flush()
sw.AutoFlush = True
Catch ex As Exception
Throw ex
End Try
Try
sw.Write(xml)
sw.Flush()
sw.Close()
Catch ex As Exception
Throw ex
End Try
wr.Timeout = 120000
Try
Dim wres As HttpWebResponse = wr.GetResponse
Dim s As IO.Stream
s = wres.GetResponseStream
Dim sr As IO.StreamReader
sr = New IO.StreamReader(s)
Return sr.ReadToEnd
Catch ex As Exception
Throw ex
End Try
-Daryl
"Two More Rolls of Duct tape, and the world is mine!"
VB.NET Guru
-
May 17th, 2004, 11:29 AM
#4
Thread Starter
Addicted Member
Oh yeah, Here's MyPolicy
Code:
Imports System.Net
Imports System.Security.Cryptography.X509Certificates
Public Class MyPolicy
Implements ICertificatePolicy
Public Function CheckValidationResult(ByVal srvPoint As ServicePoint, ByVal cert As X509Certificate, ByVal request As WebRequest, ByVal problem As Integer) As Boolean Implements ICertificatePolicy.CheckValidationResult
Return True
End Function
End Class
-Daryl
"Two More Rolls of Duct tape, and the world is mine!"
VB.NET Guru
-
May 17th, 2004, 02:55 PM
#5
yay gay
and this?
cert = System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromCertFile("C:\Cert\ca.cer")
What does the file have inside?
\m/  \m/
-
May 17th, 2004, 07:27 PM
#6
Thread Starter
Addicted Member
ca.cer is a file the web site emailed to me to use with their site. It is their SSL Certificate File. I think there is a way you can find it in your browser's cache if you visit the site.
In IE look at -Tools -Internet Options -Content -Certificates
Hope that Helps.
Last edited by Dmyze; May 17th, 2004 at 07:33 PM.
-Daryl
"Two More Rolls of Duct tape, and the world is mine!"
VB.NET Guru
-
May 21st, 2004, 07:04 AM
#7
yay gay
Hey, I tried finding the .CER file but I couldn't :S
People over here http://www.vbforums.com/showthread.p...hreadid=290738 say that i must buy a certificate in order to use it...do I?!
I could try to make like you and mail the guys from the webpage im trying to access but I guess they simply won't answer :S
Any ideas?
\m/  \m/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|