如何读取发布数据后,Web客户端的响应? (。净) [英] How to read a WebClient response after posting data? (.NET)
本文介绍了如何读取发布数据后,Web客户端的响应? (。净)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
看哪,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
)
这篇关于如何读取发布数据后,Web客户端的响应? (。净)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文