Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to ignore a certificate error with c# 2.0 WebClient - without the certificate
    text
    copied!<p>Using Visual Studio 2005 - C# 2.0, <code>System.Net.WebClient.UploadData(Uri address, byte[] data)</code> Windows Server 2003</p> <p>So here's a stripped down version of the code:</p> <pre class="lang-cs prettyprint-override"><code>static string SO_method(String fullRequestString) { string theUriStringToUse = @"https://10.10.10.10:443"; // populated with real endpoint IP:port string proxyAddressAndPort = @"http://10.10.10.10:80/"; // populated with a real proxy IP:port Byte[] utf8EncodedResponse; // for the return data in utf8 string responseString; // for the return data in utf16 WebClient myWebClient = new WebClient(); // instantiate a web client WebProxy proxyObject = new WebProxy(proxyAddressAndPort, true);// instantiate &amp; popuylate a web proxy myWebClient.Proxy = proxyObject; // add the proxy to the client myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); // stick some stuff in the header UTF8Encoding utf8Encoding = new UTF8Encoding(false);// create a utf8 encoding Byte[] utf8EncodedRequest = HttpUtility.UrlEncodeToBytes(fullRequestString, utf8Encoding); // convert the request data to a utf8 byte array try { utf8EncodedResponse = myWebClient.UploadData(theUriStringToUse, "POST", utf8EncodedRequest); // pass the utf8-encoded byte array responseString = utf8Encoding.GetString(utf8EncodedResponse); // get a useable string out of the response } catch (Exception e) { // some other error handling responseString = "&lt;CommError&gt;&lt;![CDATA[" + e.ToString() + "]]&gt;&lt;/CommError&gt;";// show the basics of the problem } return responseString;// return whatever ya got } </code></pre> <p>This is the error I get:</p> <blockquote> <p><strong>The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.</strong></p> </blockquote> <p>I don't have much control to see what's happening when the request goes out. I'm told that it's reaching the correct destination and there's a "certificate error". This is supposedly because there's a literal mismatch between the IP address in my request and the URL it resolves to. I have more than one IP I'm supposed to round-robin to so specifying the URL won't work. I'm not attaching a certificate - nor am I supposed to according to the endpoint owners. Per "them" the certificate error is 'normal and I am supposed to ignore it.</p> <p>The cert in question is supposedly one of the many verisign certs that is "just there" on our server. The examples I've seen for ignoring cert errors all seem to imply that the requestor is attaching a specific x509 certificate (which I'm not). </p> <p>I looked over <a href="https://stackoverflow.com/questions/721472/net-webservice-bypass-ssl-validation">.net WebService, bypass ssl validation!</a> which kinda-sorta describes my problem - except it also kinda-sorta doesn't because I don't know which certificate (if any) I should reference.</p> <p>Is there a way for me to ignore the error without actually knowing/caring what certificate is causing the problem?</p> <ul> <li><p>and please - kid gloves, small words, and "for dummies" code as I'm not exactly a heavy hitter.</p></li> <li><p>This traffic is over a private line - so my understanding is that ignoring the cert error is not as big a deal as if it were open internet traffic.</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload