Example #1
0
        /// <summary>
        /// 文件预取
        /// </summary>
        public static void prefetch()
        {
            Mac mac = new Mac(Settings.AccessKey, Settings.SecretKey);
            FusionManager fusionMgr = new FusionManager(mac);

            string[] urls = new string[] { "URL1", "URL2" };
            PrefetchRequest request = new PrefetchRequest(urls);
            PrefetchResult result = fusionMgr.Prefetch(request);
            Console.WriteLine(result);
        }
Example #2
0
        /// <summary>
        /// 文件预取
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public PrefetchResult Prefetch(PrefetchRequest request)
        {
            PrefetchResult result = new PrefetchResult();

            string url = prefetchUrl();
            string body = request.ToJsonStr();
            byte[] data = Encoding.UTF8.GetBytes(body);

            string token = Auth.createManageToken(url, null, mac);

            Dictionary<string, string> headers = new Dictionary<string, string>();
            headers.Add("Authorization", token);

            httpMgr.postData(url, headers, data, HttpManager.FORM_MIME_JSON,
                new CompletionHandler(delegate (ResponseInfo respInfo, string respJson)
                {
                    if (respInfo.StatusCode != 200)
                    {
                        Console.WriteLine(respInfo);
                    }

                    result = JsonConvert.DeserializeObject<PrefetchResult>(respJson);
                }));

            return result;
        }