Пример #1
0
 /// <summary>
 /// Constructor without encryption, username and password
 /// </summary>
 /// <param name="sh_url"></param>
 /// <param name="sh_path"></param>
 /// <param name="sh_port"></param>
 public GetJson(String sh_url, String sh_path, Int32 sh_port)
 {
     uriToOpenHAB = new UriBuilder(sh_url);
     this.sh_url = sh_url;
     this.sh_path = sh_path;
     this.sh_port = sh_port;
     try
     {
         uriToOpenHAB = new UriBuilder(sh_url);
     }
     catch (ArgumentNullException ex)
     {
         //Happens when the HostName could not parsed
     }
     catch (FormatException ex)
     {
         //Is equal to UriFormatException
     }
     httpClient = new HttpClient();
     Windows.Web.Http.Headers.HttpNameValueHeaderValue cacheControl = new Windows.Web.Http.Headers.HttpNameValueHeaderValue("Cache-Control", "must-revalidate");
     Windows.Web.Http.Headers.HttpNameValueHeaderValue uft8Encoding = new Windows.Web.Http.Headers.HttpNameValueHeaderValue("charset", "utf-8");
     httpClient.DefaultRequestHeaders.CacheControl.Add(cacheControl);
     httpClient.DefaultRequestHeaders.CacheControl.Add(uft8Encoding);
 }
Пример #2
0
        //private Boolean _toastOnce = false;
        //ErrorVisualizer errorVisualizier = new ErrorVisualizer();
        #endregion
        #region Constructors
        /// <summary>
        /// Constructor with encryption username and password
        /// </summary>
        /// <param name="sh_url">URL to Server</param>
        /// <param name="sh_path">Path to JSON</param>
        /// <param name="sh_port">Serverport</param>
        /// <param name="sh_username">Username</param>
        /// <param name="sh_password">Passwort</param>
        public GetJson(String sh_url, String sh_path, Int32 sh_port, String sh_username, String sh_password, Boolean isHTTPSOn)
        {
            this.sh_url = sh_url;
            this.sh_path = sh_path;
            this.sh_port = sh_port;
            this.sh_username = sh_username;
            this.sh_passwort = sh_password;
            //this.sh_uriBuilder = new UriBuilder("http", this.sh_url, this.sh_port, "/rest/sitemaps/");
            this.secured = isHTTPSOn;
            if (secured)
            {
                try
                {
                    uriToOpenHAB = new UriBuilder(sh_url);
                }
                catch (ArgumentNullException ex)
                {
                    //Happens when the HostName could not parsed
                }
                catch (FormatException ex)
                {
                    //Is equal to UriFormatException
                }
                filter = new HttpBaseProtocolFilter();
                /**
                 * Ignore some Certifcateerrors
                 * */
                filter.IgnorableServerCertificateErrors.Add(Windows.Security.Cryptography.Certificates.ChainValidationResult.Untrusted);
                filter.IgnorableServerCertificateErrors.Add(Windows.Security.Cryptography.Certificates.ChainValidationResult.Expired);
                filter.IgnorableServerCertificateErrors.Add(Windows.Security.Cryptography.Certificates.ChainValidationResult.InvalidName);
                filter.IgnorableServerCertificateErrors.Add(Windows.Security.Cryptography.Certificates.ChainValidationResult.IncompleteChain);
                filter.ServerCredential = new PasswordCredential("winHAB", this.sh_username, this.sh_passwort);
                /**
                 * Establish HttpClient
                 * */
                httpClient = new HttpClient(filter);
                Windows.Web.Http.Headers.HttpNameValueHeaderValue cacheControl = new Windows.Web.Http.Headers.HttpNameValueHeaderValue("Cache-Control", "must-revalidate");
                Windows.Web.Http.Headers.HttpNameValueHeaderValue uft8Encoding = new Windows.Web.Http.Headers.HttpNameValueHeaderValue("charset", "utf-8");
                httpClient.DefaultRequestHeaders.CacheControl.Add(cacheControl);
                httpClient.DefaultRequestHeaders.CacheControl.Add(uft8Encoding);
            }
            else if (!secured)
            {

            }
        }
Пример #3
0
 /// <summary>
 /// Constructor with encryption but with username and password
 /// </summary>
 /// <param name="sh_url"></param>
 /// <param name="sh_path"></param>
 /// <param name="sh_port"></param>
 /// <param name="sh_username"></param>
 /// <param name="sh_password"></param>
 public GetJson(String sh_url, String sh_path, Int32 sh_port, String sh_username, String sh_password)
 {
     this.sh_username = sh_username;
     this.sh_passwort = sh_password;
     this.sh_url = sh_url;
     this.sh_path = sh_path;
     this.sh_port = sh_port;
     try
     {
         uriToOpenHAB = new UriBuilder(sh_url);
     }
     catch (ArgumentNullException ex)
     {
         //Happens when the HostName could not parsed
     }
     catch (FormatException ex)
     {
         //Is equal to UriFormatException
     }
     filter = new HttpBaseProtocolFilter();
     filter.ServerCredential = new PasswordCredential("winHAB", this.sh_username, this.sh_passwort);
     /**
      * Establish HttpClient
      * */
     httpClient = new HttpClient(filter);
     Windows.Web.Http.Headers.HttpNameValueHeaderValue cacheControl = new Windows.Web.Http.Headers.HttpNameValueHeaderValue("Cache-Control", "must-revalidate");
     Windows.Web.Http.Headers.HttpNameValueHeaderValue uft8Encoding = new Windows.Web.Http.Headers.HttpNameValueHeaderValue("charset", "utf-8");
     httpClient.DefaultRequestHeaders.CacheControl.Add(cacheControl);
     httpClient.DefaultRequestHeaders.CacheControl.Add(uft8Encoding);
 }