When reading webpage information through an application, you usually need to capture webpage data. However, there is a problem that many webpages need to log on before obtaining page data. Therefore, you need to save the current cookie, in. NET, you can use the CookieContainer object to save the Cookie information after logon. This problem can be solved by adding Cookie information each time data is sent. # Region synchronously sends data via POST // <summary> // send data via POST /// </summary> /// <param name = "Url"> url </param> /// <param name = "postDataStr"> Post Data </param> /// <param name = "cookie"> Cookie container </param>/ // <returns> </returns> public string SendDataByPost (string Url, string postDataStr, ref CookieContainer cookie) {HttpWebRequest request = (HttpWebRequest) WebRequest. create (Url); if (cookie. count = 0) {request. CookieContainer = new CookieContainer (); cookie = request. cookieContainer;} else {request. cookieContainer = cookie;} request. method = "POST"; request. contentType = "application/x-www-form-urlencoded"; request. contentLength = postDataStr. length; Stream myRequestStream = request. getRequestStream (); StreamWriter myStreamWriter = new StreamWriter (myRequestStream, Encoding. getEncoding ("gb2312"); m YStreamWriter. write (postDataStr); myStreamWriter. close (); HttpWebResponse response = (HttpWebResponse) request. getResponse (); Stream myResponseStream = response. getResponseStream (); StreamReader myStreamReader = new StreamReader (myResponseStream, Encoding. getEncoding ("UTF-8"); string retString = myStreamReader. readToEnd (); myStreamReader. close (); myResponseStream. close (); return retString ;}# endh Gion # region synchronously sends data in GET mode /// <summary> /// send data in GET mode /// </summary> /// <param name = "Url"> url </param> /// <param name = "postDataStr"> GET data </param> /// <param name = "cookie"> GET container </param> /// <returns> </returns> public string SendDataByGET (string Url, string postDataStr, ref CookieContainer cookie) {HttpWebRequest request = (HttpWebRequest) WebRequest. create (Url + (postDataStr = ""? "":"? ") + PostDataStr); if (cookie. count = 0) {request. cookieContainer = new CookieContainer (); cookie = request. cookieContainer;} else {request. cookieContainer = cookie;} request. method = "GET"; request. contentType = "text/html; charset = UTF-8"; HttpWebResponse response = (HttpWebResponse) request. getResponse (); Stream myResponseStream = response. getResponseStream (); StreamReader myStreamReader = new StreamReader (myResponseStream, Encoding. getEncoding ("UTF-8"); string retString = myStreamReader. readToEnd (); myStreamReader. close (); myResponseStream. close (); return retString ;}# endregion