Exemplo n.º 1
0
        /// <summary>
        /// Gets the page using internal .NET
        /// </summary>
        /// <param name="page">The page request.</param>
        /// <returns>true if sucessful</returns>
        private bool GetInternal(HTTPRequest page)
        {
            // Use internal code to get HTML page

            using (HTTPTransaction Page = new HTTPTransaction())
            {
                Encoding encode;
                string   strEncode = _defaultEncode;

                if (Page.HTTPGet(page))
                {
                    byte[] pageData = Page.GetData();
                    int    i;

                    if (_encoding != "")
                    {
                        strEncode            = _encoding;
                        _pageEncodingMessage = "Forced: " + _encoding;
                    }
                    else
                    {
                        encode         = System.Text.Encoding.GetEncoding(_defaultEncode);
                        _strPageSource = encode.GetString(pageData);
                        int headEnd;
                        if ((headEnd = _strPageSource.ToLowerInvariant().IndexOf("</head")) != -1)
                        {
                            if ((i = _strPageSource.ToLowerInvariant().IndexOf("charset", 0, headEnd)) != -1)
                            {
                                strEncode = "";
                                i        += 8;
                                for (; i < _strPageSource.Length && _strPageSource[i] != '\"'; i++)
                                {
                                    strEncode += _strPageSource[i];
                                }
                                _encoding = strEncode;
                            }

                            if (strEncode == "")
                            {
                                strEncode            = _defaultEncode;
                                _pageEncodingMessage = "Default: " + _defaultEncode;
                            }
                            else
                            {
                                _pageEncodingMessage = strEncode;
                            }
                        }
                    }

                    GlobalServiceProvider.Get <ILog>().Debug("HTMLPage: GetInternal encoding: {0}", _pageEncodingMessage);
                    // Encoding: depends on selected page
                    if (string.IsNullOrEmpty(_strPageSource) || strEncode.ToLowerInvariant() != _defaultEncode)
                    {
                        try
                        {
                            encode         = System.Text.Encoding.GetEncoding(strEncode);
                            _strPageSource = encode.GetString(pageData);
                        }
                        catch (System.ArgumentException e)
                        {
                            GlobalServiceProvider.Get <ILog>().Error(e);
                        }
                    }
                    return(true);
                }
                _error = Page.GetError();
                if (!string.IsNullOrEmpty(_error))
                {
                    GlobalServiceProvider.Get <ILog>().Error("HTMLPage: GetInternal error: {0}", _error);
                }
                return(false);
            }
        }
Exemplo n.º 2
0
    /// <summary>
    /// Gets the page using internal .NET
    /// </summary>
    /// <param name="page">The page request.</param>
    /// <returns>true if sucessful</returns>
    private bool GetInternal(HTTPRequest page)
    {
      // Use internal code to get HTML page

      using (HTTPTransaction Page = new HTTPTransaction())
      {
        Encoding encode;
        string strEncode = _defaultEncode;

        if (Page.HTTPGet(page))
        {
          byte[] pageData = Page.GetData();
          int i;

          if (_encoding != "")
          {
            strEncode = _encoding;
            _pageEncodingMessage = "Forced: " + _encoding;
          }
          else
          {
            encode = System.Text.Encoding.GetEncoding(_defaultEncode);
            _strPageSource = encode.GetString(pageData);
            int headEnd;
            if ((headEnd = _strPageSource.ToLower().IndexOf("</head")) != -1)
            {
              if ((i = _strPageSource.ToLower().IndexOf("charset", 0, headEnd)) != -1)
              {
                strEncode = "";
                i += 8;
                for (; i < _strPageSource.Length && _strPageSource[i] != '\"'; i++)
                {
                  strEncode += _strPageSource[i];
                }
                _encoding = strEncode;
              }

              if (strEncode == "")
              {
                strEncode = _defaultEncode;
                _pageEncodingMessage = "Default: " + _defaultEncode;
              }
              else
              {
                _pageEncodingMessage = strEncode;
              }
            }
          }

          GlobalServiceProvider.Get<ILog>().Debug("HTMLPage: GetInternal encoding: {0}", _pageEncodingMessage);
          // Encoding: depends on selected page
          if (string.IsNullOrEmpty(_strPageSource) || strEncode.ToLower() != _defaultEncode)
          {
            try
            {
              encode = System.Text.Encoding.GetEncoding(strEncode);
              _strPageSource = encode.GetString(pageData);
            }
            catch (System.ArgumentException e)
            {
              GlobalServiceProvider.Get<ILog>().Error(e);
            }
          }
          return true;
        }
        _error = Page.GetError();
        if (!string.IsNullOrEmpty(_error))
          GlobalServiceProvider.Get<ILog>().Error("HTMLPage: GetInternal error: {0}", _error);
        return false;
      }
    }