Пример #1
0
        /// <summary>
        /// Starts an asynchronous DAV-HTTP-Request.
        /// </summary>
        /// <param name="header">The DAV-Request header to used.</param>
        /// <param name="body">The DAV-Request-body to used.</param>
        /// <param name="userObject">User defined object to deliver to respose method.</param>
        /// <param name="response">A handler to call after the event completes.</param>
        public void StartRequest(DAVRequestHeader header, DAVRequestBody body, object userObject, Action <DAVRequestResult, object> response)
        {
            LastException = null;
            _relativeHost = new Uri(_host + header.RequestedResource);

            header.Headers[Header.Host] = _host.DnsSafeHost;
            // this is needed to modify some headers
            HttpWebRequest.RegisterPrefix("http", System.Net.Browser.WebRequestCreator.ClientHttp);
            HttpWebRequest.RegisterPrefix("https", System.Net.Browser.WebRequestCreator.ClientHttp);
            HttpWebRequest request = HttpWebRequest.CreateHttp(_host + header.RequestedResource);

            request.AllowReadStreamBuffering = false;
            request.Method = header.RequestedMethod.ToString();
            foreach (KeyValuePair <string, string> current in header.Headers)
            {
                // API restriction
                switch (current.Key)
                {
                case "Accept":
                    request.Accept = current.Value;
                    break;

                case "Content-Type":
                    request.ContentType = current.Value;
                    break;

                default:
                    request.Headers[current.Key] = current.Value;
                    break;
                }
            }
            if (_credit != null)
            {
                request.Credentials = _credit;
            }

            if (body != null)
            {
                request.BeginGetRequestStream(_EndRequestStream, new RequestStruct
                {
                    Callback   = response,
                    Request    = request,
                    UserObject = userObject,
                    Body       = body
                });
            }
            else
            {
                request.BeginGetResponse(_EndRequest, new RequestStruct
                {
                    Callback   = response,
                    Request    = request,
                    UserObject = userObject
                });
            }
        }
Пример #2
0
        /// <summary>
        /// Starts an asynchronous DAV-HTTP-Request.
        /// </summary>
        /// <param name="header">The DAV-Request header to used.</param>
        /// <param name="body">The DAV-Request-body to used.</param>
        /// <param name="userObject">User defined object to deliver to respose method.</param>
        /// <param name="response">A handler to call after the event completes.</param>
        public void StartRequest(DAVRequestHeader header, DAVRequestBody body, object userObject, Action<DAVRequestResult, object> response)
        {
            LastException = null;
            _relativeHost = new Uri(_host + header.RequestedResource);

            header.Headers[Header.Host] = _host.DnsSafeHost;
            // this is needed to modify some headers
            HttpWebRequest.RegisterPrefix("http", System.Net.Browser.WebRequestCreator.ClientHttp);
            HttpWebRequest.RegisterPrefix("https", System.Net.Browser.WebRequestCreator.ClientHttp);
            HttpWebRequest request = HttpWebRequest.CreateHttp(_host + header.RequestedResource);
            request.AllowReadStreamBuffering = false;
            request.Method = header.RequestedMethod.ToString();
            foreach (KeyValuePair<string, string> current in header.Headers)
            {
                // API restriction
                switch(current.Key) {
                    case "Accept":
                        request.Accept = current.Value;
                        break;
                    case "Content-Type":
                        request.ContentType = current.Value;
                        break;
                    default:
                        request.Headers[current.Key] = current.Value;
                        break;
                }
            }
            if (_credit != null)
            {
                request.Credentials = _credit;
            }

            if (body != null)
            {
                request.BeginGetRequestStream(_EndRequestStream, new RequestStruct
                {
                    Callback = response,
                    Request = request,
                    UserObject = userObject,
                    Body = body
                });
            }
            else
            {
                request.BeginGetResponse(_EndRequest, new RequestStruct
                {
                    Callback = response,
                    Request = request,
                    UserObject = userObject
                });
            }
        }
Пример #3
0
        void _EndRequestStream(IAsyncResult result)
        {
            RequestStruct  obj  = (RequestStruct)result.AsyncState;
            DAVRequestBody body = obj.Body;

            try
            {
                Stream stream = obj.Request.EndGetRequestStream(result);
                body.XmlBody.Seek(0, SeekOrigin.Begin);
                body.XmlBody.CopyTo(stream, 4096);
                stream.Close();

                obj.Request.BeginGetResponse(_EndRequest, obj);
            }
            catch (WebException we)
            {
                LastException = we;
                obj.Callback(new DAVRequestResult(this, ServerStatus.LocalFailure), obj.UserObject);
            }
        }