Answer the question
In order to leave comments, you need to log in
C# (HttpWebRequest) Get POST response as byte[]?
string postData = "post string";
byte[] data = Encoding.ASCII.GetBytes(postData);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://122.233.155.155:80");
req.Method = "POST";
req.ContentLength = postData.Length;
req.Timeout = 10000;
using (Stream stream = req.GetRequestStream()) stream.Write(data, 0, data.Length);
using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII))
{
string s = reader.ReadToEnd();
Console.WriteLine(s);
}
Answer the question
In order to leave comments, you need to log in
using System.Net;
string postData = "post string";
byte[] data = Encoding.ASCII.GetBytes(postData);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://122.233.155.155:80");
req.Method = "POST";
req.ContentLength = postData.Length;
req.Timeout = 10000;
using (Stream stream = req.GetRequestStream()) stream.Write(data, 0, data.Length);
using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
{
var buffer = new byte[response.ContentLength];
response.GetResponseStream().Read(buffer, 0, buffer.Length);
Console.WriteLine(buffer.Length);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question