这是我的代码,简单请求,响应HTTP;
string uri = "https://forum.donanimhaber.com/forumid_12/tt.htm";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = WebRequestMethods.Http.Get;
request.AllowAutoRedirect = false;
request.CookieContainer = new CookieContainer();
request.KeepAlive = true;
request.ContentType = "application/x-www-form-urlencoded";
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
string oku = readStream.ReadToEnd();
如果你去这个地址并且首先看到的网络流量是" tt.htm",在cookie部分有论坛网络会话cookie。我希望在我的程序中获得这个cookie的价值,我在网上看到了这个东西,但没有一个能起作用。谢谢。
答案 0 :(得分:-2)
string uri = "https://forum.donanimhaber.com/service/v1/session/set?version=-1&securekey=123213&projectType=Forum&forumId=12";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = WebRequestMethods.Http.Get;
request.AllowAutoRedirect = false;
request.CookieContainer = new CookieContainer();
request.KeepAlive = true;
request.ContentType = "application/x-www-form-urlencoded";
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
string oku = readStream.ReadToEnd();
foreach (Cookie cook in response.Cookies)
{
Console.WriteLine("Domain: {0}, Name: {1}, value: {2}", cook.Domain, cook.Name,cook.Value);
}