C# сохраняют идентификатор сессии по httpwebrequest

Вот почему Вы имеете дерби (теперь названный JavaDB) или sqlite - они - маленькие, простые базы данных, которые можно создать, загрузиться, тест против и уничтожить относительно быстро и просто.

27
задан AnthonyWJones 21 September 2009 в 09:19
поделиться

1 ответ

If you create a single cookie container and assign that to both your first and second request you won't need to do all that mucking about copying cookies from the response.

When cookies are set by a response the cookie container that is attached the request will receive and store those cookies. So to maintain the same session context between a series of request just maintain a single cookie container instance and use that with all the requests.

Your code becomes:-

cookieContainer = new CookieContainer();
request.CookieContainer = cookieContainer;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
  // Do stuff with response
}

then:-

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
...

request.CookieContainer = cookieContainer;
Stream writeStream = request.GetRequestStream()
56
ответ дан 28 November 2019 в 04:56
поделиться
Другие вопросы по тегам:

Похожие вопросы: