本文整理汇总了C#中System.Net.Mime.ContentType.IsHtml方法的典型用法代码示例。如果您正苦于以下问题:C# ContentType.IsHtml方法的具体用法?C# ContentType.IsHtml怎么用?C# ContentType.IsHtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Mime.ContentType
的用法示例。
在下文中一共展示了ContentType.IsHtml方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportFromWebMenu_Click
//.........这里部分代码省略.........
|(t[cdfghjklmnoprtvwz]|travel)
|u[agkmsyz]
|v[aceginu]
|w[fs]
|y[etu]
|z[amw])", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture))
{
input = "http://" + input;
}
if (!Uri.IsWellFormedUriString(input, UriKind.Absolute))
MessageBox.Show(this, "The entered URL does not appear to be correctly formatted.", "Invalid URL", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
else
url = new Uri(input, UriKind.Absolute);
}
while (url == null);
//
// Download
//
string content;
var wc = new WebClient();
bool proxyAuthAttempted = false;
while (true)
{
try
{
using (CurrentCursorScope.EnterWait())
content = wc.DownloadStringUsingResponseEncoding(url);
break;
}
catch (WebException e)
{
if (e.Status == WebExceptionStatus.ProtocolError
&& !proxyAuthAttempted)
{
var httpResponse = e.Response as HttpWebResponse;
if (httpResponse != null
&& HttpStatusCode.ProxyAuthenticationRequired == httpResponse.StatusCode)
{
proxyAuthAttempted = true;
wc.AddHttpWebRequestModifier(hwr => hwr.Proxy.Credentials = CredentialCache.DefaultCredentials);
continue;
}
}
Program.ShowExceptionDialog(e, "Import Error", this);
return;
}
}
//
// Make sure it's HTML otherwise get confirmation to proceed.
//
var typeHeader = wc.ResponseHeaders[HttpResponseHeader.ContentType];
var contentType = new ContentType(typeHeader);
if (string.IsNullOrEmpty(typeHeader) || !contentType.IsHtml())
{
var msg = string.Format(
"The downloaded resource is \u201c{0}\u201d rather than HTML, "
+ "which could produce undesired results. Proceed anyway?",
contentType.MediaType);
if (DialogResult.Yes != MessageBox.Show(this, msg, "Non-HTML Content", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation))
return;
}
//
// If it's too big (> 512KB), get confirmation to proceed.
//
var lengthHeader = wc.ResponseHeaders[HttpResponseHeader.ContentLength];
long size;
if (long.TryParse(lengthHeader, NumberStyles.None, CultureInfo.InvariantCulture, out size)
&& size > 512 * 1024)
{
var msg = string.Format(
"The downloaded resource is rather large ({0} bytes). Proceed anyway?",
size.ToString("N0"));
if (DialogResult.Yes != MessageBox.Show(this, msg, "Large Content", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation))
return;
}
//
// Load 'er up!
//
using (CurrentCursorScope.EnterWait())
{
var document = new HtmlDocument();
document.LoadHtml2(content);
Open(document);
}
_lastKnownGoodImportedUrl = url;
}