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
コード例 #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);
            }
        }
コード例 #2
0
 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);
         }
     }
 }
コード例 #3
0
ファイル: WebConnectionStream.cs プロジェクト: GroM/mono
        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;
        }
コード例 #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;
        }