Example #1
0
        /// <summary>
        /// Assigns the request body.
        /// </summary>
        /// <param name="request">The request.</param>
        private void AssignRequestBody(Request request)
        {
            if (this._httpRequest == null || this._httpRequest.Body == null)
            {
                return; // nothing to do...
            }

            string?jsonString = StreamUtility.CaptureAsStringAsync(this._httpRequest.Body).Result;

            if (string.IsNullOrWhiteSpace(jsonString))
            {
                return;
            }
            request.PostBody = jsonString;
        }
Example #2
0
        /// <summary>
        /// Captures the response body.
        /// </summary>
        /// <param name="response">The response.</param>
        /// <returns>System.String.</returns>
        public static string?CaptureResponseBody(HttpResponse?response)
        {
            if (response == null ||
                response.ContentLength == null ||
                !(response.ContentLength > 0) ||
                !response.Body.CanSeek
                )
            {
                return(null);
            }

            string?bodyContent =
                StreamUtility.CaptureAsStringAsync(response.BodyWriter.AsStream(true)).Result;

            return(bodyContent);
        }
Example #3
0
        /// <summary>
        /// Captures the request body.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.String.</returns>
        public static string?CaptureRequestBody(HttpRequest?request)
        {
            if (request == null ||
                request.ContentLength == null ||
                !(request.ContentLength > 0) ||
                !request.Body.CanSeek
                )
            {
                return(null);
            }

            string?bodyContent =
                StreamUtility.CaptureAsStringAsync(request.BodyReader.AsStream(true)).Result;

            return(bodyContent);
        }