【问题标题】:System.Net.WebException: Error: ConnectFailure (Connection timed out)System.Net.WebException:错误:ConnectFailure(连接超时)
【发布时间】:2016-06-07 05:27:34
【问题描述】:
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 + "");

但在网络上它工作正常。请帮助任何解决方案。

【问题讨论】:

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


    【解决方案1】:

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

     Result = client.DownloadString(url);
    

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

    【讨论】:

      猜你喜欢
      • 2020-08-17
      • 2018-03-20
      • 1970-01-01
      • 2018-07-24
      • 1970-01-01
      • 1970-01-01
      • 2013-05-29
      • 2013-03-30
      相关资源
      最近更新 更多