Exemplo n.º 1
0
        /// <summary>
        /// 发出Put请求
        /// </summary>
        /// <param name="url">请求路径</param>
        /// <param name="body">请求数据,将会被json序列化后放到请求报文体中</param>
        /// <param name="requestHeaders">请求额外的报文头信息</param>
        /// <param name="contentType">default to application/json</param>
        /// <returns></returns>
        public virtual async Task <HttpResponse <string> > PutAsync(
            string url,
            object body = null,
            HttpRequestHeaders requestHeaders = null,
            string contentType = "application/json"
            )
        {
            using (HttpRequestMessage requestMsg = new HttpRequestMessage(HttpMethod.Put, new Uri(url)))
            {
                requestMsg.ProcessHttpRequestHeaders(requestHeaders);
                requestMsg.Content = new StringContent(SnowLeopardJsonConvert.SerializeObject(body));
                requestMsg.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType);

                return(await SendForStringAsync(requestMsg));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 发出Delete请求
        /// </summary>
        /// <typeparam name="T">响应报文反序列类型</typeparam>
        /// <param name="url">请求路径</param>
        /// <param name="body">请求数据,将会被json序列化后放到请求报文体中</param>
        /// <param name="requestHeaders">请求额外的报文头信息</param>
        /// <param name="contentType">default to application/json</param>
        /// <param name="settings">JsonSerializerSettings</param>
        /// <returns></returns>
        public virtual async Task <HttpResponse <T> > DeleteAsync <T>(
            string url,
            object body = null,
            HttpRequestHeaders requestHeaders = null,
            string contentType = "application/json",
            JsonSerializerSettings settings = null
            )
        {
            using (HttpRequestMessage requestMsg = new HttpRequestMessage(HttpMethod.Delete, new Uri(url)))
            {
                requestMsg.ProcessHttpRequestHeaders(requestHeaders);
                requestMsg.Content = new StringContent(SnowLeopardJsonConvert.SerializeObject(body, settings));
                requestMsg.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType);

                return(await SendAsync <T>(requestMsg));
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// SetAsync
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="session"></param>
 /// <param name="key"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static async Task SetAsync <T>(this ISession session, string key, T value)
 {
     session.SetString(key, SnowLeopardJsonConvert.SerializeObject(value));
     await session.CommitAsync();
 }