/// <summary> /// Adds a new stream to this <see cref="StreamingRequest"/> containing the passed in body. /// Noop on null body or null request. /// </summary> /// <param name="request">The <see cref="StreamingRequest"/> instance to attach this body to.</param> /// <param name="body">A string containing the data to insert into the stream.</param> public static void SetBody(this StreamingRequest request, string body) { if (request == null || string.IsNullOrWhiteSpace(body)) { return; } request.AddStream(new StringContent(body, Encoding.UTF8)); }
/// <summary> /// Adds a new stream to this <see cref="StreamingRequest"/> containing the passed in body. /// Noop on null body or null request. /// </summary> /// <param name="request">The <see cref="StreamingRequest"/> instance to attach this body to.</param> /// <param name="body">An object containing the data to insert into the stream.</param> public static void SetBody(this StreamingRequest request, object body) { if (request == null || body == null) { return; } var json = JsonConvert.SerializeObject(body, SerializationSettings.BotSchemaSerializationSettings); request.AddStream(new StringContent(json, Encoding.UTF8, SerializationSettings.ApplicationJson)); }
/// <summary> /// Creates a <see cref="StreamingRequest"/> with the passed in method, path, and body. /// </summary> /// <param name="method">The HTTP verb to use for this request.</param> /// <param name="path">Optional path where the resource can be found on the remote server.</param> /// <param name="body">Optional body to send to the remote server.</param> /// <returns>On success returns a <see cref="StreamingRequest"/> with appropriate status code and body, otherwise returns null.</returns> public static StreamingRequest CreateRequest(string method, string path = null, HttpContent body = null) { if (string.IsNullOrWhiteSpace(method)) { return(null); } var request = new StreamingRequest() { Verb = method, Path = path, }; if (body != null) { request.AddStream(body); } return(request); }