예제 #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;
        }
예제 #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);
        }
예제 #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);
        }