473,796 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

exception using HTTPWebRequest with SSL

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 myHttpWebReques t As HttpWebRequest

Dim myHttpWebRespon se As HttpWebResponse

myHttpWebReques t = CType(WebReques t.Create(url), HttpWebRequest)

myHttpWebReques t.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.GetByt es(postData)

' Set the content type of the data being posted.

myHttpWebReques t.ContentType = "applicatio n/x-www-form-urlencoded"

' Set the content length of the string being posted.

myHttpWebReques t.ContentLength = byte1.Length

Dim cert As X509Certificate =
X509Certificate .CreateFromCert File("C:\Docume nts and Settings\xxx\My
Documents\Certi ficate.cer")

myHttpWebReques t.ClientCertifi cates.Add(cert)

Dim newStream As Stream = myHttpWebReques t.GetRequestStr eam()

newStream.Write (byte1, 0, byte1.Length)

' Sends the request and waits for a response.

myHttpWebRespon se = CType(myHttpWeb Request.GetResp onse(), HttpWebResponse )

Dim sr As New StreamReader(my HttpWebResponse .GetResponseStr eam)

Dim res As String = sr.ReadToEnd

Me.TextBox1.Tex t = res

End Sub
Feb 22 '07 #1
0 1403

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
750
by: superseed | last post by:
Hi, I'm currently coding in C# a class to control a PTZ (Pan Tilt Zoom) Camera. To control the camera I have to send request on a CGI on it. Something like this : http://xxxxxx/axis-cgi/com/ptz.cgi?pan=100 (GET method) or using POST. To do that I'm using the HttpWebRequest and HttpWebResponse class of
1
1596
by: Chakra Venkatesan | last post by:
Hi, I am getting an exception in my ASP.NET application as shown below, at System.Threading.WaitHandle.WaitOneNative(IntPtr waitHandle, UInt32 millisecondsTimeout, Boolean exitContext) at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext) at System.Net.HttpWebRequest.GetRequestStream()
3
9904
by: Jason | last post by:
I'm having a hard time getting a call to HttpWebRequest's GetRequestSteam to work. Each time I try to run it, I get the following error: The underlying connection was closed: Unable to connect to the remote server. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more
1
1634
by: iana_kosio | last post by:
Hi, I am using HttpWebRequest class to communicate with remote server. In some cases the server would return 5xx status code which results in HttpWebRequest object throwing an exception. I, however, still need to access the response stream from the server as it contains information that I need. Any ideas how I can do that? Thanks, Konstantin try { HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://localhost/myUrl");
7
2707
by: Chuck Hartman | last post by:
I have a Windows service that requests web pages from a site using an HttpWebRequest object. When I try to request a page from an ASP.NET 2 site, I get a WebException with message "The remote server returned an error: (500) Internal Server Error." I found a post that suggested to catch the WebException to retrieve the actual HttpWebResponse object for more information. The response returned is shown below. At first I thought this was a...
3
4080
by: Rahul Anand | last post by:
As per our requirements we have a web service which internally connects (Simple HTTP Post Request) to a remote server to initiate some work. We are calling the web service method asynchronously from a .NET Web Application hosted on IIS. In our setup the web request form a client can be running for long duration (may be more than 4 hours). We are getting exceptions during the HTTP send/receive inside the web service method. The exception...
0
1626
by: Raymondr | last post by:
Hi, First a brief description of out application: We have a webapplication which calls a couple of webservices during one request (postback). These calls to the webservices are made concurrent using asynchronous webservices calls. The number of webservices called concurrent is between 1 and 18. The webservice calls are made using SSL with a X509 clientcertificate. The application is underhigh load
2
2597
by: pedrito | last post by:
I've got an app that downloads from several concurrent threads. Occasionally, I get an expcetion trying to read the HttpWebResponse stream... Sorry, the code isn't short, but I figured best to provide the whole method. This is run within its own thread. "Job" is a class that receives the information about the downloaded pages. The exception happens on the read where it says "EXCEPTION HERE"
7
2561
by: pedrito | last post by:
I get exception trying to parse this URI: http://-eeayr4mwvtw998.usercash.com/ But IE and Firefox have no problem opening it. The parse exception is actually happening inside an HTTPWebRequest so I guess there's no much I can do about it one wary or the other, unless there's some way to encode it so that it still goes where it's supposed to go but is actually parseable by the URI parser as well.
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9531
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10187
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7553
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.