Using System. Net;
Using System. IO;
Using System. Text;
[STAThread]
Static void Main (string [] args)
{
String url = "http://hi.baidu.com/yimeng3025/test.asp ";
String indata = "aa = zhuye ";
String outdata = "";
CookieContainer myCookieContainer = new CookieContainer ();
String 8
// Create a CookieContainer to store the Cookie set
HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest. Create (url );
// Create an HttpWebRequest
MyHttpWebRequest. ContentType = "application/x-www-form-urlencoded ";
MyHttpWebRequest. ContentLength = indata. Length;
MyHttpWebRequest. Method = "POST ";
MyHttpWebRequest. CookieContainer = myCookieContainer;
// Set CookieContainer of HttpWebRequest to the myCookieContainer just created
Stream myRequestStream = myHttpWebRequest. GetRequestStream ();
StreamWriter myStreamWriter = new StreamWriter (myRequestStream, Encoding. GetEncoding ("gb2312 "));
MyStreamWriter. Write (indata );
// Write data to the Request stream of HttpWebRequest
MyStreamWriter. Close ();
MyRequestStream. Close ();
// Close the open object
HttpWebResponse myHttpWebResponse = (HttpWebResponse) myHttpWebRequest. GetResponse ();
String 9
// Create an HttpWebResponse
MyHttpWebResponse. Cookies = myCookieContainer. GetCookies (myHttpWebRequest. RequestUri );
// Obtain the CookieCollection of a Cookie set containing a url
Stream myResponseStream = myHttpWebResponse. GetResponseStream ();
StreamReader myStreamReader = new StreamReader (myResponseStream, Encoding. GetEncoding ("gb2312 "));
Outdata = myStreamReader. ReadToEnd ();
// Read the data from the Response stream of HttpWebResponse
MyStreamReader. Close ();
MyResponseStream. Close ();
Console. WriteLine (outdata );
// Display "Logon"
// Get the Cookie and then perform the request to directly read the Post-Logon content.
MyHttpWebRequest = (HttpWebRequest) WebRequest. Create (url );
MyHttpWebRequest. CookieContainer = myCookieContainer ;//*
// The CookieContainer that just now has a Cookie, which can be directly verified by attaching it to HttpWebRequest.
MyHttpWebResponse = (HttpWebResponse) myHttpWebRequest. GetResponse ();
String 1
MyHttpWebResponse. Cookies = myCookieContainer. GetCookies (myHttpWebRequest. RequestUri );
MyResponseStream = myHttpWebResponse. GetResponseStream ();
MyStreamReader = new StreamReader (myResponseStream, Encoding. GetEncoding ("gb2312 "));
Outdata = myStreamReader. ReadToEnd ();
MyStreamReader. Close ();
MyResponseStream. Close ();
Console. WriteLine (outdata );
// Display "Logon" again"
// If you annotate the line *, it will display "No Logon"
}