Esempio n. 1
0
        /// <summary>
        /// 发送请求数据
        /// </summary>
        /// <param name="request">请求对象</param>
        /// <param name="postData">请求发送的字节数组</param>
        private void PostData(HttpWebRequest request, byte[] postData)
        {
            int             offset         = 0;
            int             sendBufferSize = bufferSize;
            int             remainBytes    = 0;
            Stream          stream         = request.GetRequestStream();
            UploadEventArgs args           = new UploadEventArgs();

            args.TotalBytes = postData.Length;
            while ((remainBytes = postData.Length - offset) > 0)
            {
                if (sendBufferSize > remainBytes)
                {
                    sendBufferSize = remainBytes;
                }
                stream.Write(postData, offset, sendBufferSize);
                offset += sendBufferSize;
                if (this.UploadProgressChanged != null)
                {
                    args.BytesSent = offset;
                    this.UploadProgressChanged(this, args);
                }
            }
            stream.Close();
        }
Esempio n. 2
0
 /// <summary>    
 /// 发送请求数据    
 /// </summary>    
 /// <param name="request">请求对象</param>    
 /// <param name="postData">请求发送的字节数组</param>    
 private void PostData(HttpWebRequest request, byte[] postData)
 {
     int offset = 0;
     int sendBufferSize = bufferSize;
     int remainBytes = 0;
     Stream stream = request.GetRequestStream();
     UploadEventArgs args = new UploadEventArgs();
     args.TotalBytes = postData.Length;
     while ((remainBytes = postData.Length - offset) > 0)
     {
         if (sendBufferSize > remainBytes) sendBufferSize = remainBytes;
         stream.Write(postData, offset, sendBufferSize);
         offset += sendBufferSize;
         if (this.UploadProgressChanged != null)
         {
             args.BytesSent = offset;
             this.UploadProgressChanged(this, args);
         }
     }
     stream.Close();
 }