public static void SetCookie <T>(string strKey, T obj, string strDomain = "", DateTime?expiresDate = null, string strPath = "/") where T : class { string strValue = EncryptHelper.Encrypt(SerializationHelper.ToJson(obj)); expiresDate = expiresDate ?? DateTime.Now.AddHours(7); SetCookie(strKey, strValue, strDomain, expiresDate.Value, strPath); }
public TResult PostAsync <TResult, TPostData>(string strUrl, TPostData postData, RequestType requestType, AuthenticationHeaderValue authenticationHeaderValue = null) where TResult : class { return(AjaxAsync <TResult, TPostData>(strUrl, postData, requestType, (client, responseAsync) => { HttpContent content; switch (requestType) { case RequestType.Form: //content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); content = new FormUrlEncodedContent(postData as IEnumerable <KeyValuePair <string, string> >); break; case RequestType.Json: default: string postJsonData = string.Empty; if (postData is object) { postJsonData = SerializationHelper.ToJson(postData); } else { postJsonData = postData.ToString(); } content = new StringContent(postJsonData, Encoding.UTF8); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); break; } using (HttpResponseMessage response = client.PostAsync(strUrl, content).Result) { return responseAsync(response); } }, authenticationHeaderValue)); }
public static string ToJson <TModel>() where TModel : class, new() { TModel model = new TModel(); return(SerializationHelper.ToJson(model)); }