Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android WebRequest GetRequestStream()挂起,但不在调试版本中_Android_Xamarin_Webrequest - Fatal编程技术网

Android WebRequest GetRequestStream()挂起,但不在调试版本中

Android WebRequest GetRequestStream()挂起,但不在调试版本中,android,xamarin,webrequest,Android,Xamarin,Webrequest,我在VS2015上使用Xamarin 我对GetRequestStream()的调用一直挂起,直到超时,但仅在发布版本时挂起。调试版本没有这个问题 请看下面我是如何使用它的-我在下面使用了GetResponse(),但它从未实现 日志中唯一的内容是,每隔30秒(我使用的时间间隔): 我的代码是: WebRequest client = WebRequest.Create(string.Format(REQUEST_URL, function)); client.P

我在VS2015上使用Xamarin

我对GetRequestStream()的调用一直挂起,直到超时,但仅在发布版本时挂起。调试版本没有这个问题

请看下面我是如何使用它的-我在下面使用了GetResponse(),但它从未实现

日志中唯一的内容是,每隔30秒(我使用的时间间隔):

我的代码是:

        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.");

当我调试时,甚至只是使用调试构建时,它每次都能工作。此外,它总是在模拟器上工作。

您的清单中是否启用了InternetPermissions?这是在Debug中自动完成的,但不是在release中!非常感谢。
        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.");