C# 如何解决此问题:无法识别 URI 前缀
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15217940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to solve this :The URI prefix is not recognized
提问by hitarth
When I am going to add some website like http://www.nirmauni.ac.in/
, then it says the above mentioned error. So, how to fix this problem?
I have given my code. Just go through and say where the change should be made.
当我要添加一些网站时http://www.nirmauni.ac.in/
,它会显示上述错误。那么,如何解决这个问题呢?我已经给出了我的代码。只需通过并说明应该在哪里进行更改。
bool IsLinkWorking(string url)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
//You can set some parameters in the "request" object...
request.AllowAutoRedirect = true;
ServicePointManager.ServerCertificateValidationCallback = (s, cert, chain, ssl) => true;
try
{
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
return true;
}
catch
{
//TODO: Check for the right exception here
return false;
}
}
采纳答案by Sachin
From Your Error It seems that you are creating a web request with wrong url.
从您的错误看来,您正在创建一个带有错误 url 的 Web 请求。
Please make sure that in (HttpWebRequest)HttpWebRequest.Create(url);
url string must start with proper protocol like (http,https etc.)
请确保在(HttpWebRequest)HttpWebRequest.Create(url);
url 字符串中必须以正确的协议开头,如(http、https 等)