EndReadBody() public method

public EndReadBody ( IAsyncResult result ) : int
result IAsyncResult
return int
Example #1
0
        public void Can_read_body_manually()
        {
            IRequest r = new Req {
                BodyString = "I am the posted body"
            };

            // grab some bytes ...
            byte[]       bytes     = new byte[5];
            IAsyncResult result    = r.BeginReadBody(bytes, 0, 5, null, null); // no callback or state, we want to do this synchronously
            int          bytesRead = r.EndReadBody(result);                    // this should block!  per: http://msdn.microsoft.com/en-us/library/ms228967(v=VS.80).aspx

            Assert.That(Encoding.UTF8.GetString(bytes), Is.EqualTo("I am "));

            // grab the rest
            byte[] moreBytes = new byte[1000];
            result    = r.BeginReadBody(moreBytes, 5, 1000, null, null); // no callback or state, we want to do this synchronously
            bytesRead = r.EndReadBody(result);                           // this should block!  per: http://msdn.microsoft.com/en-us/library/ms228967(v=VS.80).aspx
            Assert.That(Encoding.UTF8.GetString(WithoutTrailingBytes(moreBytes)), Is.EqualTo("the posted body"));
        }
Example #2
0
        public void Can_read_body_manually()
        {
            IRequest r = new Req { BodyString = "I am the posted body" };

            // grab some bytes ...
            byte[] bytes = new byte[5];
            IAsyncResult result = r.BeginReadBody(bytes, 0, 5, null, null); // no callback or state, we want to do this synchronously
            int bytesRead = r.EndReadBody(result); // this should block!  per: http://msdn.microsoft.com/en-us/library/ms228967(v=VS.80).aspx
            Assert.That(Encoding.UTF8.GetString(bytes), Is.EqualTo("I am "));

            // grab the rest
            byte[] moreBytes = new byte[1000];
            result = r.BeginReadBody(moreBytes, 5, 1000, null, null); // no callback or state, we want to do this synchronously
            bytesRead = r.EndReadBody(result); // this should block!  per: http://msdn.microsoft.com/en-us/library/ms228967(v=VS.80).aspx
            Assert.That(Encoding.UTF8.GetString(WithoutTrailingBytes(moreBytes)), Is.EqualTo("the posted body"));
        }