public Stream IssueRequest(string url, Method method, string body, HttpHeader[] headers)
        {
            if ( _exceptionToThrow != null )
                throw _exceptionToThrow;

            if (!string.IsNullOrEmpty(_validUrl) && !_validUrl.Equals(url))
                throw new Exception("Invalid URL used");

            if (_method != method)
            {
                string msg = string.Format("Invalid Method: {0}", method.Name);
                throw new Exception(msg);
            }

            return _response;
        }
        /// <summary>
        /// Issue a requet to the networking implementation
        /// </summary>
        /// <param name="url">The URL to request</param>
        /// <param name="method">The HTTP method to use</param>
        /// <param name="body">The request body to send</param>
        /// <returns>The response read into string body</returns>
        public string IssueRequestAndFetchReponse(
            string url,
            Method method,
            string body)
        {
            Stream stream = _requestor.IssueRequest(url, method, body, null);

            using (StreamReader reader = new StreamReader(stream))
            {
                string result = reader.ReadToEnd();

                reader.Close();
                stream.Close();

                return result;
            }
        }
 /// <summary>
 /// Issue a requet to the networking implementation
 /// </summary>
 /// <param name="url">The URL to request</param>
 /// <param name="method">The HTTP method to use</param>
 /// <param name="body">The request body to send</param>
 /// <returns>void</returns>
 public void IssueRequestIgnoreResponse(
     string url,
     Method method,
     string body)
 {
     _requestor.IssueRequest(url, method, body, null).Close();
 }
 /// <summary>
 /// Issue a requet to the networking implementation
 /// </summary>
 /// <param name="url">The URL to request</param>
 /// <param name="method">The HTTP method to use</param>
 /// <param name="body">The request body to send</param>
 /// <param name="headers">Optional headers to add to the request</param>
 /// <returns>void</returns>
 public void IssueRequestIgnoreResponse(
     string url,
     Method method,
     string body,
     HttpHeader[] headers)
 {
     _requestor.IssueRequest(url, method, body, headers).Close();
 }
 /// <summary>
 /// Issue a requet to the networking implementation
 /// </summary>
 /// <param name="url">The URL to request</param>
 /// <param name="method">The HTTP method to use</param>
 /// <param name="body">The request body to send</param>
 /// <param name="headers">Optional headers to add to the request</param>
 /// <returns>The response body</returns>
 public Stream IssueRequest(string url, Method method, string body, HttpHeader[] headers)
 {
     return _requestor.IssueRequest(url, method, body, headers);
 }
 /// <summary>
 /// Issue a requet to the networking implementation
 /// </summary>
 /// <param name="url">The URL to request</param>
 /// <param name="method">The HTTP method to use</param>
 /// <param name="body">The request body to send</param>
 /// <returns>The response body</returns>
 public Stream IssueRequest(string url, Method method, string body)
 {
     return _requestor.IssueRequest(url, method, body, null);
 }
        /// <summary>
        /// Issue a request to the URL and return the response
        /// </summary>
        /// <param name="url">The URL to make a request to</param>
        /// <param name="method">The HTTP verb to use</param>
        /// <param name="body">The request body to use</param>
        /// <param name="headers">Optional headers to add to the request</param>
        /// <returns>The response body</returns>
        public Stream IssueRequest(string url, Method method, string body, HttpHeader[] headers)
        {
            int remainingAttempts = maxRedirects;

            while (remainingAttempts > 0)
            {
                log.DebugFormat(
                    "Issuing WebDAV Request: {0} to {1} - Group {2}",
                    method.Name, url, connectionGroup);

                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);

                // Handle redirects manually
                request.AllowAutoRedirect = false;
                request.KeepAlive = true;

                // This is necesssary to make Windows Authentication
                // use keep alive. Due to the large number of
                // connections we may make to Exchange, if we don't do this,
                // the process may exhaust the supply of available ports. To keep
                // this "safe", requests are isolated by connection pool. See:
                // http://msdn2.microsoft.com/en-us/library/system.net.httpwebrequest.unsafeauthenticatedconnectionsharing.aspx
                request.UnsafeAuthenticatedConnectionSharing = true;
                request.ConnectionGroupName = connectionGroup;


                // BUG: Exchange sometimes serves different content based on the user agent so
                // we have to fake being IE?!?!?!
                request.UserAgent =
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 2.0.50727)";

                request.Credentials = credentials;
                request.Method = method.Name;
                request.Accept = "*/*";
                if (headers != null)
                {
                    foreach (HttpHeader httpHeader in headers)
                    {
                        request.Headers.Add(httpHeader.Name, httpHeader.Value);
                    }
                }

                // Set request body if t here is one
                if (!string.IsNullOrEmpty(body))
                {
                    byte[] bodyBytes = Encoding.UTF8.GetBytes(body);

                    request.ContentType = "text/xml";

                    using (Stream writer = request.GetRequestStream())
                    {
                        writer.Write(bodyBytes, 0, bodyBytes.Length);
                        writer.Close();
                    }
                }

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                switch (response.StatusCode)
                {
                    case HttpStatusCode.Found:
                    case HttpStatusCode.Moved:
                    case HttpStatusCode.RedirectKeepVerb:
                    case HttpStatusCode.RedirectMethod:
                        url = response.GetResponseHeader("Location");

                        if (response.GetResponseStream() != null)
                            response.GetResponseStream().Close();
                        response.Close();

                        if (!string.IsNullOrEmpty(ConfigCache.ExchangeDefaultDomain))
                        {
                            // If a default domain is provided, don't redirect outside it
                            Uri uri = new Uri(url);
                            if (!uri.Host.EndsWith(ConfigCache.ExchangeDefaultDomain))
                            {
                                throw new WebException("Cannot redirect outside the default domain");
                            }
                        }

                        log.DebugFormat(
                            "Redirect: {0} to {1} status {2}",
                            method, url, response.StatusCode);

                        // Preserve the credentials and verb though all types
                        // of redirects for WebDAV
                        remainingAttempts--;
                        break;

                    default:
                        return response.GetResponseStream();
                }
            }

            return new MemoryStream();
        }
示例#8
0
 /// <summary>
 /// Issue a requet to the networking implementation
 /// </summary>
 /// <param name="url">The URL to request</param>
 /// <param name="method">The HTTP method to use</param>
 /// <param name="body">The request body to send</param>
 /// <param name="headers">Optional headers to add to the request</param>
 /// <returns>The response body</returns>
 public Stream IssueRequest(string url, Method method, string body, HttpHeader[] headers)
 {
     return(_requestor.IssueRequest(url, method, body, headers));
 }
示例#9
0
 /// <summary>
 /// Issue a requet to the networking implementation
 /// </summary>
 /// <param name="url">The URL to request</param>
 /// <param name="method">The HTTP method to use</param>
 /// <param name="body">The request body to send</param>
 /// <returns>The response body</returns>
 public Stream IssueRequest(string url, Method method, string body)
 {
     return(_requestor.IssueRequest(url, method, body, null));
 }