यहाँ एक त्वरित परीक्षण है:
XAML:
<Label Content="{Binding ElementName=window_name, Path=SourceTest}"></Label>
<Label Content="{Binding ElementName=window_name, Path=SourceTest2}"></Label>
कोड:
string source_url = "http://thepiratebay.sx/search/documentary";
WebClient webpage = new WebClient();
SourceTest = webpage.DownloadString(source_url);
if (SourceTest == "")
SourceTest = "stream was empty.";
source_url = "http://www.google.com";
webpage = new WebClient();
SourceTest2 = webpage.DownloadString(source_url);
if (SourceTest2 == "")
SourceTest2 = "stream was empty.";
आपका यूआरएल एक खाली स्ट्रिंग वापस करेगा, दूसरी ओर Google, आपको वह स्रोत देगा जो आप ढूंढ रहे हैं।
संपादित करें: जैसा कि मैंने माना, आपको एक वेब ब्राउज़र की तरह पहचान करने की आवश्यकता है। यह आपकी क्वेरी के साथ काम करता है:
string source_url = "http://thepiratebay.sx/search/documentary/0/99/0";
using (var webpage = new WebClient())
{
webpage.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
SourceTest = webpage.DownloadString(source_url);
}
यहां ठीक काम करता है। –
ठीक काम करना चाहिए। आपका अपेक्षित परिणाम क्या है? –
WebClient ठीक काम करता है, के रूप में आप एक खाली स्ट्रिंग मिलता है कि यह शायद एक यूआरएल गलती है –