首页 > 解决方案 > Xamarin 表单中的 System.Net.WebExceptionStatus 异常

问题描述

我正在尝试使用HttpClient登录。我正在使用蜂窝数据连接 (3G) 将数据发送到我的服务器。当我使用数据而不是 Wifi 连接时,会出现此错误。造成这种情况的原因是什么?以及将来如何避免这种情况?

System.Net.WebException: 在 System.Net.WebConnection.HandleError (System.Net.WebExceptionStatus st, System.Exception e, System.String where) [0x00000] in :0 在 System.Net.WebConnection.ReadDone (System.IAsyncResult结果)[0x00000] in :0 at System.Net.Sockets.SocketAsyncResult+<>c.b__27_0(System.Object 状态)[0x00000] in :0 at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [ 0x00000] in <3ba84c786fec4b0f80feecce6261cf51>:0 at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00000] in <3ba84c786fec4b0f80feecce6261cf51>:0 at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <3ba84c786fec4b0f80feecce6261cf51>:0

 var link = "http://" + ipaddress + Constants.requestUrl + "Host=" + hostName + "&Database=" + database + "&Request=7ZEGvK";
 string contentType = "application/json";
 JObject json = new JObject
 {
    { "User", userName },
    { "Password", password },
    { "Code", Constants.deviceID }
 };

 HttpClient client = new HttpClient();
 var response = await client.PostAsync(link, new StringContent(json.ToString(), Encoding.UTF8, contentType));

标签: c#xamarinxamarin.formshttpclient

解决方案


推荐阅读