有些网站必须登录才能获取到页面内容。
代码如下,可获取数据。
var url = "https://yunda-api-test.appspot.com/int/parcel?wait=true"; var uid = "[email protected]"; 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);
获取数据得到 如下图
时间: 2024-10-09 21:13:57