Csharp/C Sharp by API/System.Net/HttpWebResponse — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:12, 26 мая 2010
Содержание
HttpWebResponse.Cookies
using System;
using System.Net;
public class CookieDemo {
public static void Main(string[] args) {
HttpWebRequest req = (HttpWebRequest) WebRequest.Create("yourURL");
req.CookieContainer = new CookieContainer();
HttpWebResponse resp = (HttpWebResponse) req.GetResponse();
Console.WriteLine("Number of cookies: " + resp.Cookies.Count);
Console.WriteLine("{0,-20}{1}", "Name", "Value");
for(int i=0; i < resp.Cookies.Count; i++)
Console.WriteLine("{0, -20}{1}", resp.Cookies[i].Name, resp.Cookies[i].Value);
resp.Close();
}
}
HttpWebResponse.GetResponseStream()
using System;
using System.Net;
using System.IO;
public class WebApp {
public static void Main() {
String page = "http://www.yoursite.net/index.html";
HttpWebRequest site = (HttpWebRequest)WebRequest.Create(page);
HttpWebResponse response =(HttpWebResponse)site.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader read = new StreamReader(dataStream);
String data = read.ReadToEnd();
Console.WriteLine(data);
}
}
HttpWebResponse.Headers.AllKeys
using System;
using System.Net;
public class HeaderDemo {
public static void Main() {
HttpWebRequest req = (HttpWebRequest) WebRequest.Create("http://www.osborne.ru");
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
string[] names = resp.Headers.AllKeys;
Console.WriteLine("{0,-20}{1}\n", "Name", "Value");
foreach(string n in names)
Console.WriteLine("{0,-20}{1}", n, resp.Headers[n]);
resp.Close();
}
}
HttpWebResponse.LastModified
using System;
using System.Net;
public class HeaderDemo12 {
public static void Main() {
HttpWebRequest req = (HttpWebRequest)
WebRequest.Create("http://www.Microsoft.ru");
HttpWebResponse resp = (HttpWebResponse)
req.GetResponse();
Console.WriteLine("Last modified: " + resp.LastModified);
resp.Close();
}
}