Maintaining a session when using .NET to initiate a web request

xiaoxiao2021-03-06  73

Generally use the .NET C # initiated a web request to use the WebClient class, it should be used very simple, but every time the OpenRead will enable a new session in the server, you can use HttpWebRequest cookieContainer to let multiple web requests only one session is httpwebrequest specified A cookieContainer, using the same cookiecontainer Request is a session code as follows: 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-93386.html

New Post(0)