/// <summary> /// Creates a new <see cref="HttpRequestMessage"/> to call the url <code>requestUri</code> with the HTTP /// verb <code>method</code> (GET, POST, PUT, DELETE) and data <code>payload</code>. /// </summary> protected HttpRequestMessage BuildRequest(HttpMethod method, string requestUri, object payload, params ParameterDefinition[] parameterDefinitions) { var request = BuildRequestInternal(method, requestUri, parameterDefinitions); if (payload != null) { request.Content = new PushStreamContent((outputStream, content, context) => { using (var sw = new StreamWriter(outputStream, Encoding.UTF8, 64 * 1024, false)) { RestClientHelper.CreateJsonSerializer().Serialize(sw, payload); } }, new MediaTypeWithQualityHeaderValue(MimeTypeJson)); } return(request); }
/// <summary> /// Creates a new <see cref="HttpRequestMessage"/> for http verb <paramref name="method"/> based on the <paramref name="relativeUri"/> /// and extended by possible additional query parameters represented by <paramref name="parameterDefinitions"/> /// The body of the HTTP message is provided by the <paramref name="payload"/> parameter. /// </summary> private static HttpRequestMessage CreateInternal(HttpMethod method, string relativeUri, Payload payload, KeyValuePair <string, string>[] additionalHttpRequestHeader, params ParameterDefinition[] parameterDefinitions) { var request = SetParametersAndHeaders(method, relativeUri, additionalHttpRequestHeader, parameterDefinitions); if (payload != Payload.Empty) { request.Content = new PushStreamContent((outputStream, content, context) => { using (var sw = new StreamWriter(outputStream, Encoding.UTF8, 64 * 1024, false)) { RestClientHelper.CreateJsonSerializer().Serialize(sw, payload.Value); } }, new MediaTypeWithQualityHeaderValue(RestClient.MimeTypeJson)); } return(request); }