System.Net.WebException: Error: ConnectFailure (Connection timed out)
System.Net.WebException: Error: ConnectFailure (Connection timed out)
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 + "");
但在网络上它工作正常。请帮助任何解决方案。
Web 客户端可能无法连接,因为您在 url 周围使用了双引号。您可以在此处 MDSN WebClient.DownloadString Method (String) 的 API 文档中阅读此内容。还包括一个样本。请尝试将您的线路更改为:
Result = client.DownloadString(url);
但是,我看到了您的 url 请求。您应该永远不要 在URL 查询字符串中发送用户名和密码。请至少考虑使用 Basic Authentication over HTTPS 作为最简单的用户身份验证方法,将用户名和密码放入 HTTP 授权 header.
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 + "");
但在网络上它工作正常。请帮助任何解决方案。
Web 客户端可能无法连接,因为您在 url 周围使用了双引号。您可以在此处 MDSN WebClient.DownloadString Method (String) 的 API 文档中阅读此内容。还包括一个样本。请尝试将您的线路更改为:
Result = client.DownloadString(url);
但是,我看到了您的 url 请求。您应该永远不要 在URL 查询字符串中发送用户名和密码。请至少考虑使用 Basic Authentication over HTTPS 作为最简单的用户身份验证方法,将用户名和密码放入 HTTP 授权 header.