コード例 #1
0
 /// <summary>
 /// 获取TOKEN
 /// </summary>
 /// <returns></returns>
 public virtual bool GetToken()
 {
     if (string.IsNullOrEmpty(UserID) && string.IsNullOrEmpty(Password))
     {
         throw new Exception("没有提供用户名和密码,不能获取Token ");
     }
     using (var client = new GZipWebClient())
     {
         string url = RepoUri.TrimEnd('/') + "/" + "tokens/";
         client.Encoding = System.Text.Encoding.UTF8;
         client.Headers.Add("accept", "application/json;charset=utf-8");
         client.Headers.Add("content-type", "application/json;charset=utf-8;");
         var ts      = GetTimestamp(DateTime.Now);
         var content = JsonConvert.SerializeObject(new
         {
             userid    = UserID,
             password  = Password,
             timestamp = ts,
         });
         var retBytes = client.UploadData(url, "POST", System.Text.ASCIIEncoding.UTF8.GetBytes(content));
         var ret      = JsonConvert.DeserializeObject <CommandResult <TokenInfo> >(System.Text.ASCIIEncoding.UTF8.GetString(retBytes));
         if (ret.Result == ResultCode.Successful && ret.Value != null)
         {
             TokenInfo.Tokens[RepoUri] = ret.Value;
             return(true);
         }
         throw new Exception("获取token失败 ");
     }
 }
コード例 #2
0
 protected virtual string GetControllerUrl()
 {
     return(RepoUri.TrimEnd('/') + "/" + typeof(TEntity).Name + "s/");
 }