本文整理汇总了C#中System.Net.Mime.ContentType.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ContentType.ToString方法的具体用法?C# ContentType.ToString怎么用?C# ContentType.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Mime.ContentType
的用法示例。
在下文中一共展示了ContentType.ToString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanFormatResponse
public bool CanFormatResponse(ContentType acceptHeaderElement, bool matchCharset, out ContentType contentType)
{
if (acceptHeaderElement == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("acceptHeaderElement");
}
// Scrub the content type so that it is only mediaType and the charset
string charset = acceptHeaderElement.CharSet;
contentType = new ContentType(acceptHeaderElement.MediaType);
contentType.CharSet = this.DefaultContentType.CharSet;
string contentTypeStr = contentType.ToString();
if (matchCharset &&
!string.IsNullOrEmpty(charset) &&
!string.Equals(charset, this.DefaultContentType.CharSet, StringComparison.OrdinalIgnoreCase))
{
return false;
}
if (this.contentTypeMapper != null &&
this.contentTypeMapper.GetMessageFormatForContentType(contentType.MediaType) == this.ContentFormat)
{
return true;
}
if (this.Encoder.IsContentTypeSupported(contentTypeStr) &&
(charset == null || contentType.CharSet == this.DefaultContentType.CharSet))
{
return true;
}
contentType = null;
return false;
}
示例2: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
throw new ArgumentNullException("context");
if (Feed == null)
throw new InvalidOperationException("FeedFormatter must not be null");
HttpResponseBase response = context.HttpContext.Response;
ContentType contentType = new ContentType { MediaType = "application/atom+xml", CharSet = "utf-8" };
response.Clear();
response.StatusCode = (int) HttpStatusCode.OK;
response.ContentType = contentType.ToString();
SyndicationFeedFormatter formatter = Feed.GetAtom10Formatter();
using (XmlWriter xmlWriter = XmlWriter.Create(response.Output, new XmlWriterSettings { Encoding = Encoding.UTF8 }))
formatter.WriteTo(xmlWriter);
}
示例3: DeregisterNodeAtNeighbour
private static async Task DeregisterNodeAtNeighbour(string hostname, int port)
{
var uriBuilder = new UriBuilder(Uri.UriSchemeHttp, hostname, port, "/deregisterNode");
var req = WebRequest.Create(uriBuilder.Uri) as HttpWebRequest;
req.Method = WebRequestMethods.Http.Post;
var contentTypeObj = new ContentType(MediaTypeNames.Text.Plain);
contentTypeObj.CharSet = Encoding.ASCII.WebName;
req.ContentType = contentTypeObj.ToString();
var reqBodyData = Encoding.ASCII.GetBytes(nodeGuid.ToString());
req.ContentLength = reqBodyData.LongLength;
using (var reqStream = await req.GetRequestStreamAsync())
{
await reqStream.WriteAsync(reqBodyData, 0, reqBodyData.Length);
await reqStream.FlushAsync();
}
using (var resp = await req.GetResponseAsync()) { }
}
示例4: SetContentType
public static void SetContentType(this HttpListenerResponse myResponse, ContentType myContentType)
{
myResponse.ContentType = myContentType.ToString();
}
示例5: Equals
bool Equals (ContentType other)
{
return other != null && ToString () == other.ToString ();
}
示例6: ToStringTest2
public void ToStringTest2 ()
{
ContentType dummy = new ContentType ("text/plain; charset=us-ascii");
Assert.AreEqual ("text/plain; charset=us-ascii", dummy.ToString ());
}
示例7: SendBodyWithAlternateViews
private void SendBodyWithAlternateViews (MailMessage message, string boundary, bool attachmentExists)
{
AlternateViewCollection alternateViews = message.AlternateViews;
string inner_boundary = GenerateBoundary ();
ContentType messageContentType = new ContentType ();
messageContentType.Boundary = inner_boundary;
messageContentType.MediaType = "multipart/alternative";
if (!attachmentExists) {
SendHeader (HeaderName.ContentType, messageContentType.ToString ());
SendData (String.Empty);
}
// body section
AlternateView body = null;
if (message.Body != null) {
body = AlternateView.CreateAlternateViewFromString (message.Body, message.BodyEncoding, message.IsBodyHtml ? "text/html" : "text/plain");
alternateViews.Insert (0, body);
StartSection (boundary, messageContentType);
}
try {
// alternate view sections
foreach (AlternateView av in alternateViews) {
string alt_boundary = null;
ContentType contentType;
if (av.LinkedResources.Count > 0) {
alt_boundary = GenerateBoundary ();
contentType = new ContentType ("multipart/related");
contentType.Boundary = alt_boundary;
contentType.Parameters ["type"] = av.ContentType.ToString ();
StartSection (inner_boundary, contentType);
StartSection (alt_boundary, av.ContentType, av.TransferEncoding);
} else {
contentType = new ContentType (av.ContentType.ToString ());
StartSection (inner_boundary, contentType, av.TransferEncoding);
}
switch (av.TransferEncoding) {
case TransferEncoding.Base64:
byte [] content = new byte [av.ContentStream.Length];
av.ContentStream.Read (content, 0, content.Length);
#if TARGET_JVM
SendData (Convert.ToBase64String (content));
#else
SendData (Convert.ToBase64String (content, Base64FormattingOptions.InsertLineBreaks));
#endif
break;
case TransferEncoding.QuotedPrintable:
byte [] bytes = new byte [av.ContentStream.Length];
av.ContentStream.Read (bytes, 0, bytes.Length);
SendData (ToQuotedPrintable (bytes));
break;
case TransferEncoding.SevenBit:
case TransferEncoding.Unknown:
content = new byte [av.ContentStream.Length];
av.ContentStream.Read (content, 0, content.Length);
SendData (Encoding.ASCII.GetString (content));
break;
}
if (av.LinkedResources.Count > 0) {
SendLinkedResources (message, av.LinkedResources, alt_boundary);
EndSection (alt_boundary);
}
if (!attachmentExists)
SendData (string.Empty);
}
} finally {
if (body != null)
alternateViews.Remove (body);
}
EndSection (inner_boundary);
}
示例8: SendWithAttachments
private void SendWithAttachments (MailMessage message) {
string boundary = GenerateBoundary ();
// first "multipart/mixed"
ContentType messageContentType = new ContentType ();
messageContentType.Boundary = boundary;
messageContentType.MediaType = "multipart/mixed";
messageContentType.CharSet = null;
SendHeader (HeaderName.ContentType, messageContentType.ToString ());
SendData (String.Empty);
// body section
Attachment body = null;
if (message.AlternateViews.Count > 0)
SendWithoutAttachments (message, boundary, true);
else {
body = Attachment.CreateAttachmentFromString (message.Body, null, message.BodyEncoding, message.IsBodyHtml ? "text/html" : "text/plain");
message.Attachments.Insert (0, body);
}
try {
SendAttachments (message, body, boundary);
} finally {
if (body != null)
message.Attachments.Remove (body);
}
EndSection (boundary);
}
示例9: StartSection
private void StartSection (string section, ContentType sectionContentType, TransferEncoding transferEncoding, ContentDisposition contentDisposition) {
SendData (String.Format ("--{0}", section));
SendHeader ("content-type", sectionContentType.ToString ());
SendHeader ("content-transfer-encoding", GetTransferEncodingName (transferEncoding));
if (contentDisposition != null)
SendHeader ("content-disposition", contentDisposition.ToString ());
SendData (string.Empty);
}
示例10: StartSection
private void StartSection (string section, ContentType sectionContentType, Attachment att, bool sendDisposition) {
SendData (String.Format ("--{0}", section));
if (!string.IsNullOrEmpty (att.ContentId))
SendHeader("content-ID", "<" + att.ContentId + ">");
SendHeader ("content-type", sectionContentType.ToString ());
SendHeader ("content-transfer-encoding", GetTransferEncodingName (att.TransferEncoding));
if (sendDisposition)
SendHeader ("content-disposition", att.ContentDisposition.ToString ());
SendData (string.Empty);
}
示例11: TestContentType
public void TestContentType(ContentType contentType, int paramCount)
{
string fieldText = contentType.ToString();
MimeFieldParameters fieldParams = new MimeFieldParameters();
Assert.DoesNotThrow(() => fieldParams.Deserialize(fieldText));
Assert.True(fieldParams.Count == paramCount);
Assert.Equal(contentType.MediaType, fieldParams[0].Value);
Assert.Equal<string>(contentType.Name, fieldParams["name"]);
Assert.DoesNotThrow(() => Compare(fieldParams, contentType.Parameters));
string fieldTextSerialized = null;
Assert.DoesNotThrow(() => fieldTextSerialized = fieldParams.Serialize());
fieldParams.Clear();
Assert.DoesNotThrow(() => fieldParams.Deserialize(fieldTextSerialized));
Assert.True(fieldParams.Count == paramCount);
Assert.DoesNotThrow(() => new ContentType(fieldTextSerialized));
}
示例12: ConnectToNodesContext
private static async Task ConnectToNodesContext(HttpListenerContext http_ctx)
{
var contentTypeObj = new ContentType(MediaTypeNames.Text.Plain);
contentTypeObj.CharSet = Encoding.ASCII.WebName;
var contentTypeString = contentTypeObj.ToString();
var reqBodyData = Encoding.ASCII.GetBytes(GetNodeSpecString(http_ctx));
var registrationTaksList = new List<Task>();
using (var bodyReader = new StreamReader(http_ctx.Request.InputStream, http_ctx.Request.ContentEncoding))
{
var bodyLineTask = bodyReader.ReadLineAsync();
for (var bodyLine = await bodyLineTask; bodyLine != null; bodyLine = await bodyLineTask)
{
bodyLineTask = bodyReader.ReadLineAsync();
var nodeAddr = bodyLine;
var colIdx = nodeAddr.LastIndexOf(':');
UriBuilder uriBuilder;
if (colIdx < 0)
uriBuilder = new UriBuilder(Uri.UriSchemeHttp, nodeAddr);
else
uriBuilder = new UriBuilder(Uri.UriSchemeHttp, nodeAddr.Substring(0, colIdx), int.Parse(nodeAddr.Substring(colIdx + 1)));
registrationTaksList.Add(ExchangeWithNode(uriBuilder.Uri, reqBodyData, contentTypeString));
}
}
await Task.WhenAll(registrationTaksList);
http_ctx.Response.StatusCode = (int)HttpStatusCode.OK;
http_ctx.Response.Close(new byte[0], willBlock: false);
}
示例13: GetContentType
/// <summary>
/// Gets the type of the content.
/// </summary>
/// <param name="acceptValue">The accept value.</param>
/// <param name="resolvedContentType">Type of the resolved content.</param>
/// <returns>The response content type</returns>
public static string GetContentType(ContentType acceptValue, ContentType resolvedContentType)
{
switch (acceptValue.MediaType)
{
case SdmxMedia.ApplicationXml:
case SdmxMedia.TextXml:
return acceptValue.ToString();
case "text/*":
return SdmxMedia.TextXml;
default:
return resolvedContentType.ToString();
}
}