/// <summary>
        /// Asynchronously sends a stream of raw events to Splunk.
        /// </summary>
        /// <returns>
        /// A <see cref="Stream"/> used to send events to Splunk.
        /// </returns>
        /// <remarks>
        /// This method the <a href="http://goo.gl/zFKzMp">POST
        /// receivers/stream</a> endpoint to send raw events to Splunk as
        /// they become available on <see cref="stream"/>.
        /// </remarks>
        public async Task SendAsync(Stream eventStream, ReceiverArgs args = null)
        {
            using (var content = new StreamContent(eventStream))
            {
                content.Headers.Add("x-splunk-input-mode", "streaming");

                using (var response = await this.Context.PostAsync(this.Namespace, StreamReceiver, content, args))
                {
                    await response.EnsureStatusCodeAsync(HttpStatusCode.OK);
                }
            }
        }
        /// <summary>
        /// Asynchronously send raw event text to Splunk.
        /// </summary>
        /// <param name="eventText">
        /// Raw event text.
        /// <param name="args">
        /// Arguments identifying the event type and destination.
        /// </param>
        /// <returns>
        /// A <see cref="Result"/> object representing the event created by
        /// Splunk.
        /// </returns>
        /// <remarks>
        /// This method uses the <a href="http://goo.gl/GPLUVg">POST
        /// receivers/simple</a> endpoint to obtain the <see cref="Result"/>
        /// that it returns.
        /// </remarks>
        public async Task <Result> SendAsync(string eventText, ReceiverArgs args = null)
        {
            using (var content = new StringContent(eventText))
            {
                using (var response = await this.Context.PostAsync(this.Namespace, SimpleReceiver, content, args))
                {
                    await response.EnsureStatusCodeAsync(HttpStatusCode.OK);

                    var reader = response.XmlReader;

                    await reader.ReadAsync();

                    if (reader.NodeType != XmlNodeType.XmlDeclaration)
                    {
                        throw new InvalidDataException(); // TODO: diagnostics
                    }

                    foreach (var name in new string[] { "response", "results", "result" })
                    {
                        await reader.ReadAsync();

                        if (!(reader.NodeType == XmlNodeType.Element && reader.Name == name))
                        {
                            throw new InvalidDataException(); // TODO: diagnostics
                        }
                    }

                    var result = new Result();
                    await result.ReadXmlAsync(reader);

                    foreach (var name in new string[] { "result", "results", "response" })
                    {
                        if (!(reader.NodeType == XmlNodeType.EndElement && reader.Name == name))
                        {
                            throw new InvalidDataException(); // TODO: diagnostics
                        }
                        await reader.ReadAsync();
                    }

                    return(result);
                }
            }
        }