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 }; } }
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); }
public void SetReadStream(Stream stream, bool canDispose = true) { ReadStream?.Dispose(); ReadStream = new EncryptedStream(stream, canDispose); }
public void SetWriteStream(Stream stream, bool canDispose = true) { WriteStream?.Dispose(); WriteStream = new EncryptedStream(stream, canDispose); }