Пример #1
0
        /// <summary>
        /// 发出一次新的WOSPut请求,并返回获得的回应
        /// 返回结果包含oid和状态信息.
        /// </summary>
        /// <returns>相应的HttpWosPutResponse</returns>
        public HttpWosPutOidResponse ExecuteWosPutOidRequest(String oid)
        {
            try
            {
                HttpWebRequest req = CreateWosPutOidRequest(oid);
                if (req != null)
                {
                    HttpWebResponse res = (HttpWebResponse)req.GetResponse();

                    HttpWosPutOidResponse rsp = new HttpWosPutOidResponse();
                    rsp.XDdnOid    = res.Headers.Get("x-ddn-oid");
                    rsp.XDdnStatus = res.Headers.Get("x-ddn-status");

                    return(rsp);
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                //
                return(null);
            }
        }
Пример #2
0
        public HttpWosPutOidResponse ExecuteBackGroundWosPutOidStream(BackgroundWorker bgw, String oid)
        {
            HttpWebRequest        req = (HttpWebRequest)WebRequest.Create(url);
            HttpWosPutOidResponse rsp = new HttpWosPutOidResponse();

            if (upfile != null)
            {
                int iStep = GetStepSize(upfile.Data.Length);

                req.Method      = "POST";
                req.ContentType = "application/octet-stream";
                req.Headers.Add("x-ddn-policy: test");
                req.Headers.Add("x-ddn-oid: " + oid);

                req.AllowWriteStreamBuffering = false;
                req.Timeout       = 3000000;
                req.ContentLength = upfile.Data.Length;

                Stream postStream = req.GetRequestStream();

                for (int i = 0; i < upfile.Data.Length; i += iStep)
                {
                    postStream.Write(upfile.Data, i, (upfile.Data.Length - i) > iStep ? iStep : (upfile.Data.Length - i));
                    Thread.Sleep(1);
                    bgw.ReportProgress(i / iStep);
                }
                bgw.ReportProgress((int)Math.Ceiling((double)upfile.Data.Length / (double)iStep));

                postStream.Close();
                HttpWebResponse res = (HttpWebResponse)req.GetResponse();

                rsp.XDdnOid    = res.Headers.Get("x-ddn-oid");
                rsp.XDdnStatus = res.Headers.Get("x-ddn-status");
            }
            else
            {
                return(null);
            }

            return(rsp);
        }