WebRequest GetRequestStream() hangs, but not in debug builds

134 Views Asked by At

I'm using Xamarin, on VS2015

My call to GetRequestStream() hangs until timeout, but only on release builds. Debug builds don't have the issue.

See below for how I'm using it - I'm using GetResponse() below that, but it never gets there.

The only thing in the log is this, every 30 seconds (the interval I'm using):

Sending 53 bytes of post data...

And my code:

        WebRequest client = WebRequest.Create(string.Format(REQUEST_URL, function));
        client.Proxy = null;
        client.ContentType = "application/json";
        client.Method = "POST";
        client.ContentType = "application/x-www-form-urlencoded";

        // Password
        string postData = string.Format("email={0}&password={1}", HttpUtility.UrlEncode(email), HttpUtility.UrlEncode(password));
        var data = Encoding.UTF8.GetBytes(postData);
        client.ContentLength = data.Length;

        // Write data
        Log.Debug("AppName", "Sending "+data.Length+" bytes of post data...");
        using (var stream = client.GetRequestStream()) {
            Log.Debug("AppName", "Acquired stream...");
            stream.Write(data, 0, data.Length);
        }
        Log.Debug("AppName", "Post data sent.");

When I'm debugging, or even just using a debug build, it works every time. Additionally, it always works on the emulator.

0

There are 0 best solutions below