예제 #1
0
        /// <summary>
        /// Инициализирует новый экземпляр класса <see cref="MultipartContent"/>.
        /// </summary>
        /// <param name="boundary">Граница для отделения составных частей содержимого.</param>
        /// <exception cref="System.ArgumentNullException">Значение параметра <paramref name="boundary"/> равно <see langword="null"/>.</exception>
        /// <exception cref="System.ArgumentException">Значение параметра <paramref name="boundary"/> является пустой строкой.</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">Значение параметра <paramref name="boundary"/> имеет длину более 70 символов.</exception>
        public MultipartContent(string boundary)
        {
            #region Проверка параметров

            if (boundary == null)
            {
                throw new ArgumentNullException("boundary");
            }

            if (boundary.Length == 0)
            {
                throw ExceptionHelper.EmptyString("boundary");
            }

            if (boundary.Length > 70)
            {
                throw ExceptionHelper.CanNotBeGreater("boundary", 70);
            }

            #endregion

            _boundary = boundary;

            _contentType = string.Format("multipart/form-data; boundary={0}", _boundary);
        }
예제 #2
0
 public BytesContent(byte[] content, int offset, int count)
 {
     if (content == null)
     {
         throw new ArgumentNullException("content");
     }
     if (offset < 0)
     {
         throw ExceptionHelper.CanNotBeLess("offset", 0);
     }
     if (offset > content.Length)
     {
         throw ExceptionHelper.CanNotBeGreater("offset", content.Length);
     }
     if (count < 0)
     {
         throw ExceptionHelper.CanNotBeLess("count", 0);
     }
     if (count > content.Length - offset)
     {
         throw ExceptionHelper.CanNotBeGreater("count", content.Length - offset);
     }
     _content     = content;
     _offset      = offset;
     _count       = count;
     _contentType = "application/octet-stream";
 }
예제 #3
0
 public MultipartContent(string boundary)
 {
     if (boundary == null)
     {
         throw new ArgumentNullException("boundary");
     }
     if (boundary.Length == 0)
     {
         throw ExceptionHelper.EmptyString("boundary");
     }
     if (boundary.Length > 70)
     {
         throw ExceptionHelper.CanNotBeGreater("boundary", 70);
     }
     _boundary    = boundary;
     _contentType = $"multipart/form-data; boundary={_boundary}";
 }