Last active
August 29, 2015 14:26
-
-
Save st0326s/986b2f24181e5242a836 to your computer and use it in GitHub Desktop.
Unity C# HttpwebRequestでhttps通信(オレオレ証明書エラーを回避) ref: http://qiita.com/satotin/items/a5392d04d2edad74f6ad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TlsException: Invalid certificate received from server. Error code: 0xffffffff800b010f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Net.Security; | |
using System.Security.Cryptography.X509Certificates; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 信頼できないSSL証明書を「問題なし」にするメソッド | |
private bool OnRemoteCertificateValidationCallback( | |
Object sender, | |
X509Certificate certificate, | |
X509Chain chain, | |
SslPolicyErrors sslPolicyErrors) | |
{ | |
return true; // 「SSL証明書の使用は問題なし」と示す | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ServicePointManager.ServerCertificateValidationCallback = | |
new RemoteCertificateValidationCallback(OnRemoteCertificateValidationCallback); | |
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URLをここに書く); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy(); | |
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URLをここに書く); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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