c# - 尝试创建HttpWebRequest时,System.dll中发生了 'System.UriFormatException'类型的未处理异常

标签 c# visual-studio compiler-errors

这是我的代码,我尝试模拟对URL的网站访问,并尝试了很多,如Facebook,Google,Youtube,Blogger,甚至Microsoft和一些论坛。
当我按下应用程序中的按钮以获取LinkURL.Text并执行以下操作时,代码中存在错误。 VS中的错误日志中没有错误

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(LinkURL.Text);
        request.Credentials = CredentialCache.DefaultNetworkCredentials;
        request.Timeout = 1000;
        request.Method = "Get";
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        using (StreamReader URLReader = new StreamReader(response.GetResponseStream()))
        {
            String RequestSent = URLReader.ReadToEnd();
        }

按下按钮后,此行在VS2015中显示错误
            HttpWebResponse response (HttpWebResponse)request.GetResponse();


An unhandled exception of type 'System.UriFormatException' occurred in System.dll

有什么建议?我是否缺少在此处输入的一些详细信息?
我只需要“暂时”将其计为一次访问,有时我会从网站上获取一些字符串,但是我现在不需要,只需访问即可。

最佳答案

如果您尝试访问网站时说使用按钮,则可以使用using system.diagnostic;。

然后在btnClick中使用

system.diagnostic.process.start("http://www.facebook.com/")

然后,这将使您在单击按钮时进入人 Facebook 。

关于c# - 尝试创建HttpWebRequest时,System.dll中发生了 'System.UriFormatException'类型的未处理异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37890616/

相关文章:

c# - AutoMapper Custom Resolver 在构造函数中请求可选参数

c# - 将 WCF 服务添加到网站项目

javascript - 如何让javascript不断检查更新?

c# - 编译库而不检查引用

c++ - C++中的运行时错误字符串声明

image - 图片在Heroku上停止加载

c# - 从表达式中获取字符串属性名称

c# - 以编程方式在按钮上设置图像

visual-studio - 如何解决此错误 : Loading the include file 'EF.Utility.CS.ttinclude' returned a null or empty string

c++ - 编译器不会提示函数没有返回值