How to read a WebClient response after posting data?

前端 未结 2 2084
死守一世寂寞
死守一世寂寞 2021-02-18 17:51

Behold the code:

using (var client = new WebClient())
{
    using (var stream = client.OpenWrite(\"http://localhost/\", \"POST\"))
    {
        stream.Write(pos         


        
2条回答
  •  爱一瞬间的悲伤
    2021-02-18 18:17

    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)

提交回复
热议问题