Stream os = null; try { // send the Post webRequest.ContentLength = bytes.Length; //Count bytes to send os = webRequest.GetRequestStream(); os.Write(bytes, 0, bytes.Length); //Send it } catch (WebException ex) { //ex.Message = "Failed to send data to "+url+". Because " + ex.Message; throw ex; } finally { if (os != null) { os.Close(); } } try { // get the response HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); if (webResponse == null) { return null; } StreamReader sr = new StreamReader(webResponse.GetResponseStream()); MyWebInfo.CookiesContainer.Add(webResponse.Cookies); return sr.ReadToEnd().Trim();
MyWebInfo.CookiesContainer
webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.Method = "POST"; // webRequest.CookieContainer = new CookieContainer(); webRequest.CookieContainer = MyWebInfo.CookiesContainer; byte[] bytes = Encoding.ASCII.GetBytes(parameters);