private void button3_Click(object sender, EventArgs e) { // Postvars byte[] buffer = Encoding.ASCII.GetBytes("test=postvar&test2=another"); //byte[] buffer = Encoding.ASCII.GetByteCount(label1.Text); //Initialization, we use localhost HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://127.0.0.1/MyWebS.asmx"); //Our method is post, otherwise the buffer (postvars) would be useless WebReq.Method = "POST"; //We use form contentType, for the postvars. WebReq.ContentType = "application/x-www-form-urlencoded"; //The length of the buffer (postvars) is used as contentlength. WebReq.ContentLength = buffer.Length; //We open a stream for writing the postvars Stream PostData = WebReq.GetRequestStream(); //Now we write PostData.Write(buffer, 0, buffer.Length); // Afterwards, we close. Closing is always important! PostData.Close(); //Get the response handle //HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse(); //Let's show some information about the response //Console.WriteLine(WebResp.StatusCode); //Console.WriteLine(WebResp.Server); //Now, we read the response (the string), and output it. //Stream Answer = WebResp.GetResponseStream(); //StreamReader _Answer = new StreamReader(Answer); //Console.WriteLine(_Answer.ReadToEnd()); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)