c# - 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));
解决方案
推荐阅读
- excel - 如何计算唯一的呼叫者数量(按代理)但如果呼叫者存在于另一个代理名称下的另一个表上,那么不要将其视为他的呼叫者?
- c# - 从 URL 读取 XML 数据
- go - 创建处理程序是如何工作的?
- asynchronous - Vuex 状态更改不会触发页面上的反应
- runtime-error - 如何配置 alfresco 以运行脚本任务
- python - 在 Python 中,range(1, 100, *10) 不起作用?
- javascript - window.location.reload 后如何在 Cordova 中清除意图
- unity3d - 从常规 WWW 切换到 UnityWebRequest 问题
- java - 在常量池中操作字符串与在非常量池中操作字符串 - 性能
- c# - 如何编写包含项目列表的 Xamarin 表单页面,其中每个项目都可以在其中包含事务?