C# System.Net.WebException无法解析google.com

C# System.Net.WebException无法解析google.com,c#,windows-8.1,C#,Windows 8.1,目标平台:Windows 8.1 我有这个简单的代码 using System; using System.IO; using System.Net; using System.Diagnostics public static async void DownloadFile(string url) { HttpWebRequest request = WebRequest.CreateHttp(url); WebResponse

目标平台:Windows 8.1

我有这个简单的代码

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行中得到一个System.Net.WebException

其他信息:无法解析远程名称:“www.google.com”


每个url都会发生这种情况。是的,我的电脑有互联网,不,我没有使用代理,我怀疑google.com没有被防火墙解雇。

很明显,这是DNS问题。您可以在命令行中使用nslookup www.google.com检查它是否正常工作。

您可以尝试刷新DNS缓存-ipconfig/flushdnst,这没有帮助,但谢谢您。也许您的程序正被防火墙阻止。。。尝试在防火墙规则中为您的程序添加异常记住添加*.vshost.exe您是在模拟器上运行还是仅在本地计算机上运行?@fillobotto在两者上都发生OP表示每个URL都会发生异常,然后检查防火墙,或者您可以直接尝试使用IP地址,看看它是否正常工作。