发布数据后如何读取WebClient响应? [英] How to read a WebClient response after posting data?

查看:33
本文介绍了发布数据后如何读取WebClient响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看代码:

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?

推荐答案

您似乎要发布一个 byte [] 数据;在这种情况下,我希望您会发现它更易于使用:

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 -也许是 Encoding.UTF8 )

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

这篇关于发布数据后如何读取WebClient响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆