This class contains data for events that happen in the context of an HTTP response.
Inheritance: System.EventArgs
Exemplo n.º 1
0
        /// <summary>
        /// This method provides the handling for the <see cref="IHttpApiRequest.AfterAsyncWebResponse"/> event
        /// sent by the underlying <see cref="HttpApiCall"/>.
        /// </summary>
        /// <remarks>
        /// The default implementation of this method sends the <see cref="AfterAsyncWebResponse"/>
        /// event for the current instance.
        /// </remarks>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        protected virtual void HandleAfterAsyncWebResponse(object sender, HttpResponseEventArgs e)
        {
            var handler = AfterAsyncWebResponse;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Exemplo n.º 2
0
        public static void HandleAfterAsyncWebResponse(object sender, HttpResponseEventArgs e)
        {
            if (e.Response.Status == TaskStatus.RanToCompletion)
            {
                if (SuppressOutput)
                {
                    if (e.Response.Result.IsSuccessStatusCode)
                        return;
                    else
                        LogRequest(e.Response.Result.RequestMessage);
                }

                Console.Error.WriteLine("{0} (Result {1})", DateTime.Now, e.Response.Result.StatusCode);

                if (e.Response.Result.Content != null && e.Response.Result.Content.Headers.ContentType != null)
                {
                    switch (e.Response.Result.Content.Headers.ContentType.MediaType)
                    {
                    case "application/json":
                        LogResult(e.Response.Result, e.Response.Result.Content.ReadAsStringAsync().Result, true);
                        break;

                    case "application/xml":
                    case "text/plain":
                    case "text/html":
                        LogResult(e.Response.Result, e.Response.Result.Content.ReadAsStringAsync().Result, false);
                        break;

                    default:
                        LogResult(e.Response.Result, "[STREAMING CONTENT]", false);
                        break;
                    }
                }
                else
                {
                    LogResult(e.Response.Result, "[NO CONTENT]", false);
                }
            }
            else
            {
                Console.Error.WriteLine("{0} (Result {1})", DateTime.Now, e.Response.Status);
            }
        }