HttpWebRequest Timed-Out Wit.ai

Hello all,

I’ve got a weird little problem. I’m trying to make a request to Wit.ai using their API.
The code:

string GetJSONText(String filepath)
    {
        var bytes = File.ReadAllBytes(filepath);

        // create an HttpWebRequest
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.wit.ai/speech?v=20160901");

        request.Method = "POST";
        request.Headers["Authorization"] = "Bearer token";
        request.ContentType = "audio/wav";

        request.GetRequestStream().Write(bytes, 0, bytes.Length);

        // Process the wit.ai response
        try
        {
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            if (response.StatusCode == HttpStatusCode.OK)
            {
                print("Http went through ok");
                StreamReader response_stream = new StreamReader(response.GetResponseStream());
                return response_stream.ReadToEnd();
            }
            else
            {
                return "Error: " + response.StatusCode.ToString();
                return "HTTP ERROR";
            }
        }
        catch (Exception ex)
        {
            return "Error: " + ex.Message;
            return "HTTP ERROR";
        }
    }

The file being streamed is a .wav file. At request.GetResponse() I get the timed out error.
The weird thing is that when using this piece of code in a normal .net project, everything works just fine. But whenever I run it within Unity it times out. Any ideas? It doesn’t seem to be a firewall issue, as I disabled it whole.

I might have found something …

I have this running in Start

        // Mono default behavior does not trust any server;
        // the following is a workaround (there is a better solution to this issue which can be found in the Internet. 
        System.Net.ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => {
            return true;
        };