Example #1
0
        public void Load(Uri i_Uri, String i_FileName)
        {
            m_Filename = i_FileName;

            //WebClient Client = new WebClient();

            // Specify that the DownloadFileCallback method gets called
            // when the download completes.
            //Client.d += new AsyncCompletedEventHandler(DownloadFileCallback2);
            // Specify a progress notification handler.
            //Client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback);
            //Client.DownloadStringAsync(httpSite, "serverdata.txt");

            // Create the request object.
            WebRequest wreq = WebRequest.Create(i_Uri);
            // wreq.Method = "PUT";

            // Create the state object.
            RequestState rs = new RequestState();

            // Put the request into the state object so it can be passed around.
            rs.Request = wreq;
            rs.Client = this;

            // Issue the async request.
            IAsyncResult r = (IAsyncResult)wreq.BeginGetResponse(
               new AsyncCallback(RespCallback), rs);
        }
Example #2
0
        private HttpWebResponse DoStorageRequest(string i_ResourcePath, string i_HttpMethod,
            Dictionary<string, string> i_MetadataHeaders, byte[] i_Data, string i_ContentType)
        {
            // Create request object for http://<ACCOUNT>.blob.core.windows.net/<RESOURCE_PATH>
            string URL = "http://" + this.AccountName + "." + this.Host + "/" + i_ResourcePath;

            HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(URL);
            Request.Method = i_HttpMethod;

            //Request.ContentLength = (i_Data == null) ? 0 : i_Data.Length;
            Request.ContentType = i_ContentType;

            // Add x-ms-data header. This should be in RFC 1123 format,i.e.
            // of the form Sun, 28 Jan 2008 12:11:37 GMT
            // This is done by calling DataTime.ToString("R")
            Request.Headers[HeaderData] = DateTime.UtcNow.ToString("R", CultureInfo.InvariantCulture);

            // Add custom headers to request's headers
            if (i_MetadataHeaders != null)
            {
                foreach (string Key in i_MetadataHeaders.Keys)
                {
                    Request.Headers[Key] = i_MetadataHeaders[Key];
                }
            }

            // Get authorization header value by signing request
            string AuthHeader = SignRequest(Request);

            // Add authorization header
            Request.Headers["Authorization"] = "SharedKey " + this.AccountName + ":" + AuthHeader;

            RequestState State = new RequestState();
            State.Request = Request;
            State.RequestData = i_Data;
            State.Client = this;
            // Write data if any
            if (i_Data != null)
            {
                IAsyncResult StreamResult = Request.BeginGetRequestStream(new AsyncCallback(RespStreamCallback), State);

                //  AllDone.WaitOne();
            }

            IAsyncResult t = Request.BeginGetResponse(new AsyncCallback(RespCallback), State);

            return (HttpWebResponse)State.Response;
        }