Skip to content

Instantly share code, notes, and snippets.

@st0326s
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save st0326s/986b2f24181e5242a836 to your computer and use it in GitHub Desktop.
Save st0326s/986b2f24181e5242a836 to your computer and use it in GitHub Desktop.
Unity C# HttpwebRequestでhttps通信(オレオレ証明書エラーを回避) ref: http://qiita.com/satotin/items/a5392d04d2edad74f6ad
 TlsException: Invalid certificate received from server. Error code: 0xffffffff800b010f
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
// 信頼できないSSL証明書を「問題なし」にするメソッド
private bool OnRemoteCertificateValidationCallback(
Object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true; // 「SSL証明書の使用は問題なし」と示す
}
ServicePointManager.ServerCertificateValidationCallback =
     new RemoteCertificateValidationCallback(OnRemoteCertificateValidationCallback);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URLをここに書く);
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URLをここに書く);
using UnityEngine;
using System.Collections;
public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy {
public TrustAllCertificatePolicy() { }
public bool CheckValidationResult(System.Net.ServicePoint sp,
System.Security.Cryptography.X509Certificates.X509Certificate cert,
System.Net.WebRequest req,
int problem)
{
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment