【发布时间】:2020-06-09 14:14:27
【问题描述】:
我们在 xamarin android 下使用 Visual Studio 2017 构建了一个应用程序。 这个应用程序运行三年没有任何问题。
两周以来,我不知道为什么有些设备实际上无法与我们的后端同步。 这真的很奇怪,因为这部分没有任何变化。
此错误并非出现在所有设备上,而是不时出现在一两个设备上 我们使用 dll httpClient 与我们的后端同步数据。
如果我在 postAsync 中放置一个断点,我有一个例外 -> 无法访问已处置的对象。对象名称:'System.Net.Sockets.NetworkStream
有人知道如何解决这个问题吗?还有什么意思?
这是 postAsync 方法的代码: 感谢我们的时间和评论家伙
public override HttpResult ExecutePost(Uri target, string body)
{
var client = new HttpClient();
client.MaxResponseContentBufferSize = MaxHttpResponseBufferSize;
try
{
var requestContent = new StringContent(body, RequestContentEncoding, RequestContentType);
var response = client.PostAsync(target, requestContent).Result;
if (response.IsSuccessStatusCode)
{
var content = response.Content.ReadAsStringAsync().Result;
return new HttpResult(content, null, null);
}
return new HttpResult(null, "Response is empty", response.StatusCode.ToString());
}
catch (Exception e)
{
return new HttpResult(null, "Problem with the HttpPost", e.Message);
}
}
【问题讨论】:
标签: android xamarin httpclient