Skip to content

Instantly share code, notes, and snippets.

@timsonner
Last active March 30, 2025 09:53
Show Gist options
  • Save timsonner/ed1e146db773d55ad55bea63ba6fa66d to your computer and use it in GitHub Desktop.
Save timsonner/ed1e146db773d55ad55bea63ba6fa66d to your computer and use it in GitHub Desktop.
C#. Unity. Bypass SSL certificate verification of UnityWebRequest.
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