Last active
March 30, 2025 09:53
-
-
Save timsonner/ed1e146db773d55ad55bea63ba6fa66d to your computer and use it in GitHub Desktop.
C#. Unity. Bypass SSL certificate verification of UnityWebRequest.
This file contains hidden or 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 UnityEngine.Networking; | |
using TMPro; | |
using System.Collections; | |
public class NetworkRequest : MonoBehaviour | |
{ | |
public TMP_InputField ipAddressField; | |
public TMP_Text resultText; | |
public void SetupGetResponse() | |
{ | |
string ipAddress = ipAddressField.text; | |
StartCoroutine(GetResponse(ipAddress)); | |
} | |
private IEnumerator GetResponse(string ipAddress) | |
{ | |
UnityWebRequest www = UnityWebRequest.Head($"http://{ipAddress}:80"); | |
www.certificateHandler = new BypassCertificate(); | |
yield return www.SendWebRequest(); | |
if (www.result == UnityWebRequest.Result.Success) | |
{ | |
resultText.text = $"Status code: {www.responseCode}"; | |
} | |
else | |
{ | |
resultText.text = "Request failed"; | |
} | |
} | |
} | |
public class BypassCertificate : CertificateHandler | |
{ | |
protected override bool ValidateCertificate(byte[] certificateData) | |
{ | |
// Always returns true, indicating that the certificate is valid | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment