2015-04-20 31 views
1

目標平臺:Windows 8.1System.Net.WebException無法解析google.com

我這個簡單的代碼

using System; 
using System.IO; 
using System.Net; 
using System.Diagnostics 

public static async void DownloadFile(string url) 
{ 
       HttpWebRequest request = WebRequest.CreateHttp(url); 
       WebResponse resp = await request.GetResponseAsync(); 
       System.IO.Stream stream = resp.GetResponseStream(); 
       System.IO.StreamReader reader = new System.IO.StreamReader(stream); 
       Debug.WriteLine("content:" + reader.ReadToEnd()); 
} 

現在,當我這樣調用

DownloadFile("https://www.google.com/"); 

此功能它閒置了一段時間,大約過了10秒鐘後,我在GetResponseAsync-line中得到一個System.Net.WebException。

附加信息:遠程名稱無法解析:'www.google.com'

這發生在每個網址。是的,我的電腦有互聯網,沒有我不使用代理服務器,我懷疑google.com不會被防火牆取代。

+0

你可以嘗試刷新DNS緩存 - ipconfig/flushdns – Stamen

+0

這沒有幫助,但謝謝。 – Nozdrum

+2

也許你的程序是被防火牆阻止的程序...嘗試在你的程序的防火牆規則中添加一個異常(請記住添加'* .vshost.exe') –

回答

0

顯然這是一個DNS問題。您可以在命令行中使用「nslookup www.google.com」來檢查它是否正常工作。

+0

OP說,它發生在每個網址 – fillobotto

+0

比檢查防火牆,或者你可以嘗試直接使用IP地址,看看它是否工作正常。 – vxchin