这是我的代码,我尝试模拟对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/