C# 从windows应用程序访问url

C# 从windows应用程序访问url,c#,http,webclient,C#,Http,Webclient,有人知道如何从windows应用程序访问url吗 我有一个地址要从我的windows应用程序访问此页面 问候,, Harsh Suman不清楚您想对页面做什么 如果要在表单上显示它,可以使用WebBrowser控件 如果要获取响应并对其进行处理,请使用System.Net.WebClient类。不清楚要对页面执行什么操作 如果要在表单上显示它,可以使用WebBrowser控件 如果您想获得响应并对其进行处理,请使用System.Net.WebClient类。我不确定您要问什么,所以我只是用另一种

有人知道如何从windows应用程序访问url吗

我有一个地址要从我的windows应用程序访问此页面

问候,,
Harsh Suman

不清楚您想对页面做什么

如果要在表单上显示它,可以使用
WebBrowser
控件


如果要获取响应并对其进行处理,请使用
System.Net.WebClient
类。

不清楚要对页面执行什么操作

如果要在表单上显示它,可以使用
WebBrowser
控件


如果您想获得响应并对其进行处理,请使用
System.Net.WebClient
类。

我不确定您要问什么,所以我只是用另一种方式来解释问题

如果您只想启动默认浏览器(以显示本地或在线html手册等),在windows中(在其他操作系统中可能类似),您可以使用某种“执行界面”来执行格式正确的url作为命令,这通常会启动默认浏览器:

根据此代码,应启动浏览器:

string targeturl= "http://stackoverflow.com";

try
    {
     System.Diagnostics.Process.Start(targeturl);
    }
catch
    ( 
     System.ComponentModel.Win32Exception noBrowser) 
    {
     if (noBrowser.ErrorCode==-2147467259)
      MessageBox.Show(noBrowser.Message);
    }
catch (System.Exception other)
    {
      MessageBox.Show(other.Message);
    }

(错误代码的神奇数字看起来很难看,不过…

我不知道你在问什么,所以我只是用另一种方式来解释这个问题

如果您只想启动默认浏览器(以显示本地或在线html手册等),在windows中(在其他操作系统中可能类似),您可以使用某种“执行界面”来执行格式正确的url作为命令,这通常会启动默认浏览器:

根据此代码,应启动浏览器:

string targeturl= "http://stackoverflow.com";

try
    {
     System.Diagnostics.Process.Start(targeturl);
    }
catch
    ( 
     System.ComponentModel.Win32Exception noBrowser) 
    {
     if (noBrowser.ErrorCode==-2147467259)
      MessageBox.Show(noBrowser.Message);
    }
catch (System.Exception other)
    {
      MessageBox.Show(other.Message);
    }

(错误代码的神奇数字看起来很难看,但是…

如果您想下载HTML或任何文件,可以使用WebClient类

例如:

    /// <summary>
    /// Downloads a file from the given location
    /// </summary>
    /// <param name="url">Location of the file</param>
    /// <param name="dest">The destination of the downloaded file</param>
    /// <returns>False if there was an error, else True</returns>
    public bool DownLoad(string url, string dest)
    {
        WebClient client = new WebClient();
        try
        {
            //Downloads the file from the given url to the given destination                
            client.DownloadFile(url, dest);
            return true;
        }
        catch (WebException)
        {
            // Handle exception
            return false;
        }
        catch (System.Security.SecurityException)
        {
            // Handle exception
            return false;
        }
        catch (Exception)
        {
            // Handle exception
            return false;
        }
    }
//
///从给定位置下载文件
/// 
///文件的位置
///下载文件的目标
///如果有错误,则为False,否则为True
公共bool下载(字符串url、字符串dest)
{
WebClient客户端=新的WebClient();
尝试
{
//将文件从给定url下载到给定目标
client.DownloadFile(url,dest);
返回true;
}
捕获(WebException)
{
//处理异常
返回false;
}
捕获(System.Security.SecurityException)
{
//处理异常
返回false;
}
捕获(例外)
{
//处理异常
返回false;
}
}

如果要下载HTML或任何文件,可以使用WebClient类

例如:

    /// <summary>
    /// Downloads a file from the given location
    /// </summary>
    /// <param name="url">Location of the file</param>
    /// <param name="dest">The destination of the downloaded file</param>
    /// <returns>False if there was an error, else True</returns>
    public bool DownLoad(string url, string dest)
    {
        WebClient client = new WebClient();
        try
        {
            //Downloads the file from the given url to the given destination                
            client.DownloadFile(url, dest);
            return true;
        }
        catch (WebException)
        {
            // Handle exception
            return false;
        }
        catch (System.Security.SecurityException)
        {
            // Handle exception
            return false;
        }
        catch (Exception)
        {
            // Handle exception
            return false;
        }
    }
//
///从给定位置下载文件
/// 
///文件的位置
///下载文件的目标
///如果有错误,则为False,否则为True
公共bool下载(字符串url、字符串dest)
{
WebClient客户端=新的WebClient();
尝试
{
//将文件从给定url下载到给定目标
client.DownloadFile(url,dest);
返回true;
}
捕获(WebException)
{
//处理异常
返回false;
}
捕获(System.Security.SecurityException)
{
//处理异常
返回false;
}
捕获(例外)
{
//处理异常
返回false;
}
}

您想。。如何访问它?。。。阅读内容?,在应用程序中显示内容?我不太明白这个问题。你想。。如何访问它?。。。阅读内容?,在应用程序中显示内容?我不太明白这个问题。