예제 #1
0
 /// <summary>
 /// Call the specified url and mac.
 /// </summary>
 /// <param name="url">URL.</param>
 /// <param name="mac">Mac.</param>
 public string Call(string url, MAC mac)
 {
     try{
         HttpWebRequest req = this.GetWebRequest(new Uri(url)) as HttpWebRequest;
         mac.SignRequest(req, null);
         using (HttpWebResponse response = req.GetResponse() as HttpWebResponse) {
             using (StreamReader reader = new StreamReader(response.GetResponseStream())) {
                 return(reader.ReadToEnd());
             }
         }
     }catch (Exception e) {
         throw e;
     }
 }
예제 #2
0
        /// <summary>
        /// Stat the QiniuFile with mac.
        /// </summary>
        /// <param name="mac">Mac.</param>
        public QiniuFileInfo Stat(MAC mac = null)
        {
            if (mac == null)
            {
                mac = new MAC();
            }
            string url = string.Format("{0}/{1}/{2}", Config.RS_HOST, "stat", Base64URLSafe.Encode(this.bucketName + ":" + this.key));

            try {
                using (QiniuWebClient client = new QiniuWebClient()) {
                    string result = client.Call(url, mac);
                    return(GetQiniuEntry(result));
                }
            } catch (WebException e) {
                throw new QiniuWebException(e);
            }catch (Exception e) {
                throw e;
            }
        }
예제 #3
0
        /// <summary>
        /// Delete the QiniuFile with mac.
        /// </summary>
        /// <param name="mac">Mac.</param>
        public bool Delete(MAC mac = null)
        {
            if (mac == null)
            {
                mac = new MAC();
            }
            string url = string.Format("{0}/{1}/{2}", Config.RS_HOST, "delete", Base64URLSafe.Encode(this.bucketName + ":" + this.key));

            try {
                using (QiniuWebClient client = new QiniuWebClient()) {
                    client.Call(url, mac);
                    return(true);
                }
            } catch (WebException e) {
                throw new QiniuWebException(e);
            } catch (Exception e) {
                throw e;
            }
        }
예제 #4
0
        /// <summary>
        /// 生成上传Token
        /// </summary>
        /// <returns></returns>
        public string Token(MAC mac = null)
        {
            if (string.IsNullOrEmpty(persistentOps) ^ string.IsNullOrEmpty(persistentNotifyUrl))
            {
                throw new Exception("PersistentOps and PersistentNotifyUrl error");
            }
            if (string.IsNullOrEmpty(callBackUrl) ^ string.IsNullOrEmpty(callBackBody))
            {
                throw new Exception("CallBackUrl and CallBackBody error");
            }
            if (!string.IsNullOrEmpty(returnUrl) && !string.IsNullOrEmpty(callBackUrl))
            {
                throw new Exception("returnUrl and callBackUrl error");
            }
            if (mac == null)
            {
                mac = new MAC(Config.ACCESS_KEY, Config.SECRET_KEY);
            }
            this.deadline = (UInt32)((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000 + (long)expires);
            string flag = this.ToString();

            return(mac.SignWithData(Encoding.UTF8.GetBytes(flag)));
        }