C# 下面的c代码不是从给定的URL读取网站或网页

C# 下面的c代码不是从给定的URL读取网站或网页,c#,asp.net,c#-4.0,asp.net-web-api,c#-3.0,C#,Asp.net,C# 4.0,Asp.net Web Api,C# 3.0,上述代码无法读取/下载以下网页: 1. 2请注意,.aspx文件扩展名设计了服务器端页面,因此您将能够只下载在这些站点上导航时显示的html页面。这与.php文件相同 但是,如果您想下载前端视图,这应该可以: WebRequest request = WebRequest.Create(url); WebRequest.DefaultWebProxy = null; request.Proxy = null; WebRespons

上述代码无法读取/下载以下网页: 1. 2

请注意,.aspx文件扩展名设计了服务器端页面,因此您将能够只下载在这些站点上导航时显示的html页面。这与.php文件相同

但是,如果您想下载前端视图,这应该可以:

        WebRequest request = WebRequest.Create(url);
        WebRequest.DefaultWebProxy = null;

        request.Proxy = null;
        WebResponse response = request.GetResponse();
        Stream data = response.GetResponseStream();
        using (StreamReader sr = new StreamReader(data))
        {
            html = sr.ReadToEnd();
        }
这可能有助于您在以下代码中获取和发布数据:


那么它有什么作用呢?如果我知道,它以什么方式没有得到它,那么我为什么会问。那么你应该能够在getresponse之后去调试并查看响应变量。。。
using System.Net;
...
WebClient client = new WebClient();
client.DownloadFile("Your url","download location");
public static string PostContent(this Uri url, string body, string contentType = null)
    {
        var request = WebRequest.Create(url);
        request.Method = "POST";

        if (!string.IsNullOrEmpty(contentType)) request.ContentType = contentType;

        using (var requestStream = request.GetRequestStream())
        {
            if (!string.IsNullOrEmpty(body)) using (var writer = new StreamWriter(requestStream)) { writer.Write(body); }

            using (var response = request.GetResponse() as HttpWebResponse)
            {
                using (var stream = response.GetResponseStream())
                using (var reader = new StreamReader(stream))
                {
                    return reader.ReadToEnd();
                }
            }
        }
    }

    public static string GetContent(this Uri url)
    {
        WebClient client = new WebClient();
        try
        {
            using (client)
            {
                client.Encoding = Encoding.UTF8;

                return client.DownloadString(url);
            }
        }
        catch (WebException)
        {
            return "";
        }
        finally
        {
            client.Dispose();
            client = null;
        }
    }