tags:

views:

694

answers:

1

Behold the code:

using (var client = new WebClient())
{
    using (var stream = client.OpenWrite("http://localhost/", "POST"))
    {
        stream.Write(post, 0, post.Length);
    }
}

Now, how do I read the HTTP output?

+3  A: 

It looks like you have a byte[] of data to post; in which case I expect you'll find it easier to use:

byte[] response = client.UploadData(address, post);

And if the response is text, something like:

string s = client.Encoding.GetString(response);

(or your choice of Encoding - perhaps Encoding.UTF8)

Marc Gravell
It would work, if I was not trying to read an HTTP 500 response, which turns to be an exception. But your answer surely fulfills the requirements of the question.
Jader Dias
You may want to clarify the question then; it may involve using HttpWebRequest...
Marc Gravell
Question continued at http://stackoverflow.com/questions/1015020/how-to-read-an-asp-net-internal-server-error-description-with-net
Jader Dias