- Home /
HTTPS: ignore untrusted certificate?
I'm trying to connect to my server using HTTPS, but I don't have an actual proper certificate installed. In the browser I can just click "Proceed anyway" and get 128-bit encryption.
But unity gives me no such option, it just returns "SSL: certificate subject name 'localhost' does not match the target host name 'domainxyz.com'"
Is there any way to make it ignore this message and just get on with the data? Or do I have to get a proper certificate to make this work?
Answer by Diablo404 · Nov 03, 2015 at 07:33 AM
I needed the same thing. In case someone still need it, here is the answer:
IEnumerator Start ()
{
ServicePointManager.ServerCertificateValidationCallback = TrustCertificate;
HttpWebRequest request = (HttpWebRequest) WebRequest.Create( "https://yoururl.com" );
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
Stream dataStream = response.GetResponseStream ();
StreamReader reader = new StreamReader (dataStream);
string responseFromServer = reader.ReadToEnd ();
Debug.Log ("responseFromServer=" + responseFromServer );
yield return 0;
}
//http://stackoverflow.com/questions/3674692/mono-webclient-invalid-ssl-certificates
private static bool TrustCertificate(object sender, X509Certificate x509Certificate, X509Chain x509Chain, SslPolicyErrors sslPolicyErrors)
{
// all Certificates are accepted
return true;
}
I'm not sure if I'm supposed to just copy&paste this code, but much of the stuff appears red. Am I missing an import?
Looking through here, I found that I need to import IO, Net, and Security from System with:
using System.IO;
using System.IO.IsolatedStorage;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
Your answer
Follow this Question
Related Questions
SSL Ciphers? How to set reliable https Rest calls? 0 Answers
POST a form over HTTPS with unvalidated SSL Certificate 2 Answers
WWW/WWWForm, does Unity validate SSL certificates? 1 Answer
WWW/WWWForm, does Unity validate SSL certificates over HTTPS? 0 Answers
How to avoid reestablishing an HTTPS request, use Connection: Keep-Alive or reuse WWW object? 2 Answers