コード例 #1
0
ファイル: QiniuWebClient.cs プロジェクト: 15831944/winform-1
 /// <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
ファイル: QiniuFile.cs プロジェクト: 15831944/winform-1
        /// <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
ファイル: QiniuFile.cs プロジェクト: 15831944/winform-1
        /// <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
ファイル: QiniuPutPolicy.cs プロジェクト: 15831944/winform-1
        /// <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)));
        }