如何读取发布数据后,Web客户端的响应? (。净)客户端、数据、Web

2023-09-03 03:33:07 作者:那就跟紧我

看哪,code:

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

现在,我怎么读取HTTP输出?

Now, how do I read the HTTP output?

推荐答案

它看起来像你有一个字节[] 数据的发布;在这种情况下,我想你会发现它更容易使用:

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);

(或您选择编码的 - 也许 Encoding.UTF8