Android WebRequest GetRequestStream()挂起,但不在调试版本中
我在VS2015上使用Xamarin 我对GetRequestStream()的调用一直挂起,直到超时,但仅在发布版本时挂起。调试版本没有这个问题 请看下面我是如何使用它的-我在下面使用了GetResponse(),但它从未实现 日志中唯一的内容是,每隔30秒(我使用的时间间隔): 我的代码是: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
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.");