コード例 #1
0
        /// <inheritdoc/>
        public override HttpContent SerializeBody <T>(T body, RequestBodySerializerInfo info)
        {
            var content = new StringContent(JsonConvert.SerializeObject(body, this.JsonSerializerSettings));

            content.Headers.ContentType.MediaType = "application/json";
            return(content);
        }
コード例 #2
0
        /// <inheritdoc/>
        public override HttpContent?SerializeBody <T>(T body, RequestBodySerializerInfo info)
        {
            if (body == null)
            {
                return(null);
            }

            var content = new StringContent(JsonConvert.SerializeObject(body, this.JsonSerializerSettings));

            const string contentType = "application/json";

            if (content.Headers.ContentType == null)
            {
                content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
            }
            else
            {
                content.Headers.ContentType.MediaType = contentType;
            }
            return(content);
        }
コード例 #3
0
ファイル: RestClient.cs プロジェクト: zoeysaurusrex/RestEase
 public override HttpContent SerializeBody <T>(T body, RequestBodySerializerInfo info) =>
 this.serializer.SerializeBody(body);
コード例 #4
0
 /// <summary>
 /// Serialize the given request body
 /// </summary>
 /// <param name="body">Body to serialize</param>
 /// <param name="info">Extra information about the request</param>
 /// <typeparam name="T">Type of the body to serialize</typeparam>
 /// <returns>HttpContent to assign to the request</returns>
 public virtual HttpContent?SerializeBody <T>(T body, RequestBodySerializerInfo info)
 {
     throw new NotImplementedException($"You must override and implement SerializeBody<T>(T body, RequestBodySerializerInfo info) in {this.GetType().Name}");
 }
コード例 #5
0
 /// <summary>
 /// Serialize the given request body
 /// </summary>
 /// <param name="body">Body to serialize</param>
 /// <param name="info">Extra information about the request</param>
 /// <typeparam name="T">Type of the body to serialize</typeparam>
 /// <returns>HttpContent to assign to the request</returns>
 public virtual HttpContent SerializeBody <T>(T body, RequestBodySerializerInfo info)
 {
     throw new NotImplementedException("You must override and implement SerializeBody<T>(T body, RequestBodySerializerInfo info)");
 }