Example #1
0
 private HtmlDocument LoadUrl(Uri uri, string method, WebProxy proxy, NetworkCredential creds)
 {
     HtmlDocument doc = new HtmlDocument();
     doc.OptionAutoCloseOnEnd = false;
     doc.OptionFixNestedTags = true;
     _statusCode = Get(uri, method, null, doc, proxy, creds);
     if (_statusCode == HttpStatusCode.NotModified)
     {
         // read cached encoding
         doc.DetectEncodingAndLoad(GetCachePath(uri));
     }
     return doc;
 }
Example #2
0
 /// <summary>
 /// Loads an HTML document from an Internet resource.
 /// </summary>
 /// <param name="url">The requested URL, such as "http://Myserver/Mypath/Myfile.asp".</param>
 /// <param name="method">The HTTP method used to open the connection, such as GET, POST, PUT, or PROPFIND.</param>
 /// <param name="proxy">Proxy to use with this request</param>
 /// <param name="credentials">Credentials to use when authenticating</param>
 /// <returns>A new HTML document.</returns>
 public HtmlDocument Load(string url, string method, WebProxy proxy, NetworkCredential credentials)
 {
     Uri uri = new Uri(url);
     HtmlDocument doc;
     if ((uri.Scheme == Uri.UriSchemeHttps) ||
         (uri.Scheme == Uri.UriSchemeHttp))
     {
         doc = LoadUrl(uri, method, proxy, credentials);
     }
     else
     {
         if (uri.Scheme == Uri.UriSchemeFile)
         {
             doc = new HtmlDocument();
             doc.OptionAutoCloseOnEnd = false;
             doc.OptionAutoCloseOnEnd = true;
             doc.DetectEncodingAndLoad(url, _autoDetectEncoding);
         }
         else
         {
             throw new HtmlWebException("Unsupported uri scheme: '" + uri.Scheme + "'.");
         }
     }
     if (PreHandleDocument != null)
     {
         PreHandleDocument(doc);
     }
     return doc;
 }