Unity returns NULL when I try to send a HTTPS request
I'm struggling to send a HTTPS request on Unity for about 3 days. I did search a lot about it and what I understand is that Mono doesn't support SSL validation.
There is a solution for this on the internet. Putting this snippet code in above of HTTP request code.
ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true;
But, unfortunately, it's not working.
I'm using the "Http Client" asset: https://www.assetstore.unity3d.com/#!/content/79343
My code:
public string send()
{
HttpClient httpClient = new HttpClient();
ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true;
httpClient.GetString(new Uri("https://jsonplaceholder.typicode.com/todos/1"), (r) =>
{
Debug.Log(r.Data);
});
}
I would be glad If someone can help me on this. I've tried the official HTTP APIs of Unity but the result is same. Please don't suggest me to upgrade the runtime or Unity version. I'm making a Unity asset for botdelive and it should work on every version of it. By the way, I don't want to use StartCoroutine/IEnumerator.
Unity version: 2017.3.1.f1
Runtime version: .NET 3.5
Api Compatibilitiy Level: .NET 2.0 Subset
Answer by DownER149 · Dec 12, 2018 at 09:10 AM
no idea how the http client works. but try r.text or r.data.text i could tell you how to do it with the built in unity functions if that doesnt work.
if you don't use IEnumerator it doesn't wait for the data to be retrieved so it will always return null... because you didn't wait for the packet to be delivered
Your answer
Follow this Question
Related Questions
HTTP Request - error:UNITYTLS_X509VERIFY_NOT_DONE 0 Answers
Https freezes the game for one second 1 Answer
Is Unity 5.2 uses mono 4? 0 Answers
Load an image from https URL with login 0 Answers
Finish UnityWebRequest before going further in Code 1 Answer