System.Net.WebException:错误:ConnectFailure(连接超时)

时间:2016-06-07 05:27:34

标签: android asp.net-web-api xamarin xamarin.android

string dataResult = GetData("http://192.168.1.119/Test/api/TestApp/LoginCheck?username=" + UName.Text + "&pswrd=" + Pswrd.Text + "");

private string GetData(string url)
    {
        string Result = "false";
        try
        {   
            using (WebClient client = new WebClient())
            {
                Result = client.DownloadString(@"" + url + "");

            }
        }
        catch (Exception e)
        {
            string msg = e.Message;
            Result = "false";
        }
        return Result;
    }

嗨朋友我在这一行中收到连接超时错误

 Result = client.DownloadString(@"" + url + "");

但在网络上它运作良好。请帮助任何解决方案。

1 个答案:

答案 0 :(得分:0)

可能是Webclient无法连接,因为您在网址周围使用双引号。您可以在此处MDSN WebClient.DownloadString Method (String)的API文档中阅读此内容。还包括一个样本。请尝试将您的行更改为:

 Result = client.DownloadString(url);

但是,我看到了您的请求的网址。您应该从不在URL查询字符串中发送用户名和密码。请考虑至少使用基于HTTPS的Basic Authentication来验证用户的最简单方法,即将用户名和密码放在HTTP授权标头中。