你好,我在C#中構建了一個類似於webspider的東西。在我的研究中,我遇到了一個問題,如果鏈接是內部或外部,入站或出站,我需要阻止。所以我需要創建一個函數來爲我完成這項工作。所以我想出了以下功能,但我不確定它是否是最好的algorythm爲了完成任務。所以我想你對這個問題的看法。檢查一個鏈接是內部的還是外部的
我asume與沒有HTTP鏈接://或https://在鏈接前面是內部 ,如果我有一個域http://www.blahblah.com然後像測試鏈路仍然應該是內部儘管有HTTP :/ /在前面,但像http://www.somethingelse.com/?var1=http://www.blahblah.com/test鏈接是外部我正在檢查第一個字母只。
private Boolean checklinkifinternal(String link)
{
Boolean isinternal = false;
if (link.IndexOf("http://") == 0 || link.IndexOf("https://") == 0)
{
//Then probably external
if (link.IndexOf("http://" + UrlName) == 0 || link.IndexOf("https://" + UrlName) == 0 || link.IndexOf("http://www." + UrlName) == 0 || link.IndexOf("https://www." + UrlName) == 0)
{
isinternal = true;
}
}
else
{
isinternal = true;
}
return isinternal;
}
如何確定它是使用協議的外部/內部...? – Shai 2012-01-04 11:57:54
http://127.0.0.1或http://192.168.1.1什麼都是內部,但會通過作爲外部 – Lloyd 2012-01-04 11:57:57
的確沒有想到的勞埃德 – themis 2012-01-04 11:59:15