代码改变世界

获取windows身份认证网站页面内容

2016-09-08 12:17  CodeCy  阅读(496)  评论(0编辑  收藏  举报

有些网站必须登录才能获取到页面内容。

代码如下,可获取数据。

   var url = "https://yunda-api-test.appspot.com/int/parcel?wait=true";
            var uid = "1@test";
            var pwd = "97878";


            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

            request.Method = "GET";
            // Add authentication to request  
            request.Credentials = new NetworkCredential(uid, pwd);


            var text = string.Empty;
            // Get response  
            using (WebResponse response = request.GetResponse())
            {
                // Get the response stream  
                StreamReader reader = new StreamReader(response.GetResponseStream());

                // Console application output  
                text = reader.ReadToEnd();

            }



            Console.WriteLine(text);

 获取数据得到 如下图