Esempio n. 1
0
        internal HttpClient(ClientConfig config, string clientSchema, string hostname, int hostPort, string basePath)
        {
            this.version = ".NET/" + LoadVersion();
            this.handler = new HttpClientHandler()
            {
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
            };

            this.client         = new System.Net.Http.HttpClient(handler);
            this.client.Timeout = TimeSpan.FromMilliseconds(config.ClientTimeout);
            this.client.MaxResponseContentBufferSize = config.MaxResponseContentBufferSize;
            if (string.IsNullOrEmpty(config.Token))
            {
                this.credentialHandler = new ClientIdAndSecretCredentialHandler(config, client, clientSchema, hostname, hostPort);
            }
            else
            {
                this.credentialHandler = new StaticTokenCredentialHandler(config.Token);
            }

            this.compressionEnabled = config.CompressionEnabled;
            this.clientSchema       = clientSchema;
            this.hostname           = hostname;
            this.hostPort           = hostPort;
            this.basePath           = basePath;

            this.policy = config.ExponentialBackoffConfig.Policy();
        }
        private HttpWebRequest CreateWebRequest(string Url, string Request, CredentialHandler CredentialHandler = null)
        {
            // Return a web request for the given URL
            HttpWebRequest oReq = (HttpWebRequest)WebRequest.Create(Url);

            if (!(CredentialHandler == null))
            {
                CredentialHandler.ApplyCredentialsToHttpWebRequest(oReq);
            }
            oReq.AllowAutoRedirect = false;
            oReq.Method            = "POST";
            UTF8Encoding encoding = new UTF8Encoding();

            byte[] bRequest = encoding.GetBytes(Request);
            oReq.ContentType   = "text/xml; charset=utf-8";
            oReq.ContentLength = bRequest.Length;
            Stream oReqStream = oReq.GetRequestStream();

            oReqStream.Write(bRequest, 0, bRequest.Length);
            oReqStream.Close();
            oReq.Headers.Add("charset", "utf-8");

            if (_logger != null)
            {
                LogHeaders(oReq.Headers, "AutodiscoverRequestHeaders", Url);
                _logger.Log(Request, "AutodiscoverRequest");
            }

            return(oReq);
        }
Esempio n. 3
0
        public CredentialHandler CredentialHandler()
        {
            // Create a CredentialHandler object with the selected credentials
            CredentialHandler credentialHandler;

            if (radioButtonNoAuth.Checked)
            {
                credentialHandler = new CredentialHandler(AuthType.None);
            }
            else if (radioButtonCertificateAuthentication.Checked)
            {
                credentialHandler             = new CredentialHandler(AuthType.Certificate);
                credentialHandler.Certificate = _authCertificate;
            }
            else if (radioButtonOAuth.Checked)
            {
                credentialHandler            = new CredentialHandler(AuthType.OAuth);
                credentialHandler.OAuthToken = textBoxOAuthToken.Text;
            }
            else
            {
                credentialHandler          = new CredentialHandler(AuthType.Basic);
                credentialHandler.Username = textBoxUsername.Text;
                credentialHandler.Password = textBoxPassword.Text;
                if (!String.IsNullOrEmpty(textBoxDomain.Text))
                {
                    credentialHandler.Domain = textBoxDomain.Text;
                }
            }
            return(credentialHandler);
        }
Esempio n. 4
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            if (checkBoxUpdateEWSHeader.Checked)
            {
                UpdateSOAPHeader();
            }
            string sSOAPRequest   = xmlEditorRequest.Text;
            string sSOAPResponse  = "";
            string sErrorResponse = "";

            xmlEditorResponse.Text = "";
            HighlightResponseGroupbox(false);

            buttonSend.Enabled       = false;
            xmlEditorRequest.Enabled = false;
            this.Update();

            CredentialHandler credentialHandler = CredentialHandler();
            ClassSOAP         oSOAP             = new ClassSOAP(textBoxURL.Text, _logger, credentialHandler);

            SetSecurityProtocol(oSOAP);
            oSOAP.BypassWebProxy = checkBoxBypassProxySettings.Checked;
            if ((listViewHTTPHeaders.Items.Count > 0) || radioButtonOAuth.Checked)
            {
                // Add the HTTP headers
                List <string[]> headers = new List <string[]>();
                foreach (ListViewItem item in listViewHTTPHeaders.Items)
                {
                    string[] sHeader = new string[2];
                    sHeader[0] = item.Text;
                    sHeader[1] = item.SubItems[1].Text;
                    headers.Add(sHeader);
                }
                if (radioButtonOAuth.Checked)
                {
                    oSOAP.AuthorizationHeader = String.Format("Bearer {0}", textBoxOAuthToken.Text); // Add OAuth token
                }
                oSOAP.HTTPHeaders = headers;
            }

            sSOAPResponse = oSOAP.SendRequest(sSOAPRequest, out sErrorResponse, RequestCookies());

            xmlEditorResponse.Text = sSOAPResponse;
            if (!String.IsNullOrEmpty(sErrorResponse))
            {
                HighlightResponseGroupbox(true, sErrorResponse);
            }

            // Store any cookies we have had returned
            PersistCookies(oSOAP.ResponseCookies);
            UpdateHTTPCookieControls();
            UpdateHTTPHeaderControls();
            buttonSend.Enabled       = true;
            xmlEditorRequest.Enabled = true;
        }
 public ClassEWSAutodiscover(string SMTPAddress, CredentialHandler CredentialHandler, ListBox LogListBox, ClassLogger Logger)
     : this(SMTPAddress, CredentialHandler, LogListBox)
 {
     _logger = Logger;
 }
 public ClassEWSAutodiscover(string SMTPAddress, CredentialHandler CredentialHandler, ListBox LogListBox)
     : this(SMTPAddress, CredentialHandler)
 {
     _logListBox = LogListBox;
 }
 public ClassEWSAutodiscover(string SMTPAddress, CredentialHandler CredentialHandler)
     : this(SMTPAddress)
 {
     _credentialHandler = CredentialHandler;
 }
Esempio n. 8
0
 public ClassSOAP(string TargetURL, ClassLogger Logger, CredentialHandler credentialHandler)
 {
     _targetURL         = TargetURL;
     _logger            = Logger;
     _credentialHandler = credentialHandler;
 }