Topic: Secure Server Error: "The remote name could not be resolved:"
Description: Sometimes you will get an error when trying to connect to a secure web server for sending HTTPWebRequests. The following error will sometimes be generated when this happens: "The remote name could not be resolved: 'www.mywebsite.com' at System.Net.HttpWebRequest.GetRequestStream() at...
To get around this error, you need to add some certificate validation to your method that is calling the web server. In my example, I am streaming files to a secure web server (https://www.mywebsite.com)
To handle security checking add the following namespaces
using System.Net;
using System.Security.Cryptography.X509Certificates;
Create the class below inside your namespace:
public class Mypolicy : ICertificatePolicy
{
public bool CheckValidationResult(System.Net.ServicePoint srvPoint, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Net.WebRequest request, int certificationProblem)
{
return true;
}
}
Inside your method that you begin access to your secure web server, add the following code:
// This is my method that does the work to upload documents to the server
public bool Upload(List<UploadDocumentModel> DocCollection)
{
// Add this code prior to uploading to the server
System.Net.ServicePointManager.CertificatePolicy = new Mypolicy();
// Your remaining code, goes here
}