Write() private method

private Write ( HttpWebRequest request, byte buffer, int offset, int size, string &err_msg ) : bool
request HttpWebRequest
buffer byte
offset int
size int
err_msg string
return bool
Example #1
0
        internal void SetHeaders(byte [] buffer, int offset, int size)
        {
            if (headersSent)
            {
                return;
            }

            if (!allowBuffering || sendChunked)
            {
                headersSent = true;
                if (!cnc.Connected)
                {
                    throw new WebException("Not connected", null, WebExceptionStatus.SendFailure, null);
                }


                if (!cnc.Write(buffer, offset, size))
                {
                    throw new WebException("Error writing request.", null, WebExceptionStatus.SendFailure, null);
                }

                if (!initRead)
                {
                    initRead = true;
                    WebConnection.InitRead(cnc);
                }
            }
            else
            {
                headers = new byte [size];
                Buffer.BlockCopy(buffer, offset, headers, 0, size);
            }
        }
 private void WriteHeaders()
 {
     if (!headersSent)
     {
         headersSent = true;
         string err_msg = null;
         if (!cnc.Write(request, headers, 0, headers.Length, ref err_msg))
         {
             throw new WebException("Error writing request: " + err_msg, null, WebExceptionStatus.SendFailure, null);
         }
     }
 }
Example #3
0
        public override void Close()
        {
            if (sendChunked)
            {
                if (disposed)
                {
                    return;
                }
                disposed = true;
                pending.WaitOne();
                byte [] chunk   = Encoding.ASCII.GetBytes("0\r\n\r\n");
                string  err_msg = null;
                cnc.Write(request, chunk, 0, chunk.Length, ref err_msg);
                return;
            }

            if (isRead)
            {
                if (!nextReadCalled)
                {
                    CheckComplete();
                    // If we have not read all the contents
                    if (!nextReadCalled)
                    {
                        nextReadCalled = true;
                        cnc.Close(true);
                    }
                }
                return;
            }
            else if (!allowBuffering)
            {
                complete_request_written = true;
                if (!initRead)
                {
                    initRead = true;
                    WebConnection.InitRead(cnc);
                }
                return;
            }

            if (disposed || requestWritten)
            {
                return;
            }

            long length = request.ContentLength;

            if (!sendChunked && length != -1 && totalWritten != length)
            {
                IOException io = new IOException("Cannot close the stream until all bytes are written");
                nextReadCalled = true;
                cnc.Close(true);
                throw new WebException("Request was cancelled.", io, WebExceptionStatus.RequestCanceled);
            }

            // Commented out the next line to fix xamarin bug #1512
            //WriteRequest ();
            disposed = true;
        }
Example #4
0
        public override void Close()
        {
            if (GetResponseOnClose)
            {
                if (disposed)
                {
                    return;
                }
                disposed = true;
                var response = (HttpWebResponse)request.GetResponse();
                response.ReadAll();
                response.Close();
                return;
            }

            if (sendChunked)
            {
                if (disposed)
                {
                    return;
                }
                disposed = true;
                if (!pending.WaitOne(WriteTimeout))
                {
                    throw new WebException("The operation has timed out.", WebExceptionStatus.Timeout);
                }
                byte [] chunk   = Encoding.ASCII.GetBytes("0\r\n\r\n");
                string  err_msg = null;
                cnc.Write(request, chunk, 0, chunk.Length, ref err_msg);
                return;
            }

            if (isRead)
            {
                if (!nextReadCalled)
                {
                    CheckComplete();
                    // If we have not read all the contents
                    if (!nextReadCalled)
                    {
                        nextReadCalled = true;
                        cnc.Close(true);
                    }
                }
                return;
            }
            else if (!allowBuffering)
            {
                complete_request_written = true;
                if (!initRead)
                {
                    initRead = true;
                    cnc.InitRead();
                }
                return;
            }

            if (disposed || requestWritten)
            {
                return;
            }

            long length = request.ContentLength;

            if (!sendChunked && length != -1 && totalWritten != length)
            {
                IOException io = new IOException("Cannot close the stream until all bytes are written");
                nextReadCalled = true;
                cnc.Close(true);
                throw new WebException("Request was cancelled.", WebExceptionStatus.RequestCanceled, WebExceptionInternalStatus.RequestFatal, io);
            }

            // Commented out the next line to fix xamarin bug #1512
            //WriteRequest ();
            disposed = true;
        }