V
V
Vimake2014-03-04 19:34:49
C++ / C#
Vimake, 2014-03-04 19:34:49

How to get response after POST request?

System.Net.WebRequest reqPOST = System.Net.WebRequest.Create(@"http://site.ru/send.php");
reqPOST.Method = "POST"; 
reqPOST.Timeout = 120000; 
reqPOST.ContentType = "application/x-www-form-urlencoded";
byte[] sentData = Encoding.GetEncoding(1251).GetBytes("message=" + System.Web.HttpUtility.UrlEncode("отправляемые данные", Encoding.GetEncoding(1251)));
reqPOST.ContentLength = sentData.Length;
System.IO.Stream sendStream = reqPOST.GetRequestStream();
sendStream.Write(sentData, 0, sentData.Length);
sendStream.Close();
System.Net.WebResponse result = reqPOST.GetResponse();

I'm trying to get a response from the server. To which I sent a post request. But alas, in response I get System.Net.http.WebResponse

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Antonenko, 2014-07-01
@dabrahabra

To subtract the answer:

using (Stream stream = result.GetResponseStream())
{
   StreamReader reader = new StreamReader(stream, Encoding.UTF8);
   String responseString = reader.ReadToEnd();
}

Headers can be pulled from the WebResponse itself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question