I think you probably want something like
http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.servercertificatevalidationcallback.aspx

On Fri, May 28, 2010 at 1:55 PM, Tom <[email protected]> wrote:
> Hi all,
>
> I am trying to post a request to a web service over https.  The server
> has a certificate but does not require the client to have a
> certificate.  I am not interested in validating the server
> certificate.  How can I post a request to a web server using https
> without validating the server certificate?  It must be possible
> because the open source SoapUI can do it.
>
> Here is the c# code I am using.  I copied this code from MSDN.  It
> works fine for http, but throws a "The remote certificate in invalid
> according to the validation procedure" exception for https.
>
> //WebRequest request = WebRequest.Create("http://www.contoso.com/
> PostAccepter.aspx"); works fine
> WebRequest request = WebRequest.Create("https://www.webservice.com/
> ProcessMessage"); //throws exception
> request.Method = "POST";
> string postData = "This is a test that posts this string to a Web
> server.";
> byte[] byteArray = Encoding.UTF8.GetBytes(postData);
> request.ContentType = "text/xml; charset=UTF-8";
> request.ContentLength = byteArray.Length;
> Stream dataStream = request.GetRequestStream();
> dataStream.Write(byteArray, 0, byteArray.Length);
> dataStream.Close();
> WebResponse response = request.GetResponse();
> Console.WriteLine(((HttpWebResponse)response).StatusDescription);
> dataStream = response.GetResponseStream();
> StreamReader reader = new StreamReader(dataStream);
> string responseFromServer = reader.ReadToEnd();
> Console.WriteLine(responseFromServer);
> reader.Close();
> dataStream.Close();
> response.Close();
>
> Any help is appreciated.  Thanks.

Reply via email to