Maintaining a session method (reposted) when using .NET to initiate a web request

xiaoxiao2021-03-06  68

Generally use the .NET C # initiated a web request is to use the WebClient class, it should be very simple, but each time the OpenRead will enable a new session in the server.

Using httpwebrequest cookieContainer, you can let multiple web requests only have a session to specify a cookieContainer for httpwebrequest, using the same cookiecontainer Request is a session.

code show as below:

CookieContainer cc = new cookiecontainer ();

For (int i = 0; i <100; i )

{

HttpWebRequest myreq = (httpwebrequest) WebRequest.create ("http://localhost/aspxapp/mainform.aspx");

MyReq.cookiecontainer = cc;

Httpwebresponse respon = myreq.getresponse () AS httpwebresponse;

Street S = Resp.getResponsestream ();

StreamReader SR = New StreamReader (s); string text = sr.readtoend ();

sr.close ();

s.close ();

}

The content returned by this program is SessionID, which is the same as the SESSIONID.

转载请注明原文地址:https://www.9cbs.com/read-108342.html

New Post(0)