예제 #1
0
        public void Post()
        {
            if (_requestStream != null)
            {
                _requestStream.Flush();
            }

            _requestStream?.Dispose();
            _requestStream = null;

            try
            {
                _httpResponse = (HttpWebResponse)_httpRequest.GetResponse();

                if (_httpResponse.ContentType != "application/encrypted-data")
                {
                    throw new WebException("Invalid ContentType", WebExceptionStatus.ProtocolError);
                }

                var responseStream = _httpResponse.GetResponseStream();
                _responseStream = (responseStream != null)
                    ? new EncryptedStream(responseStream)
                    : null;
            }
            catch (WebException e)
            {
                _httpResponse = (HttpWebResponse)e.Response;
                if (_httpResponse != null)
                {
                    var responseStream = _httpResponse.GetResponseStream();
                    _requestStream = (responseStream != null) ? new EncryptedStream(responseStream) : null;

                    throw new HttpChannelException($"{_httpResponse.StatusCode}: {e.Message}")
                          {
                              StatusCode = (int)_httpResponse.StatusCode
                          };
                }
                throw new HttpChannelException($"{e.Status}: {e.Message}")
                      {
                          StatusCode = (int)e.Status
                      };
            }
        }
예제 #2
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                _requestStream?.Dispose();
                _requestStream = null;

                _responseStream?.Dispose();
                _responseStream = null;

                #if NETSTANDARD2_0
                _httpResponse?.Dispose();
                _httpResponse = null;
                #endif

                #if NETFX
                _httpResponse?.Close();
                _httpResponse = null;
                #endif

                _httpRequest = null;
            }
            base.Dispose(disposing);
        }
예제 #3
0
 public void SetReadStream(Stream stream, bool canDispose = true)
 {
     ReadStream?.Dispose();
     ReadStream = new EncryptedStream(stream, canDispose);
 }
예제 #4
0
 public void SetWriteStream(Stream stream, bool canDispose = true)
 {
     WriteStream?.Dispose();
     WriteStream = new EncryptedStream(stream, canDispose);
 }