本文整理汇总了C#中ContentType.ToKey方法的典型用法代码示例。如果您正苦于以下问题:C# ContentType.ToKey方法的具体用法?C# ContentType.ToKey怎么用?C# ContentType.ToKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContentType
的用法示例。
在下文中一共展示了ContentType.ToKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenUploadStreams
/// <summary>アップロードストリームを開く</summary>
/// <param name="Url">アップロードURL</param>
/// <param name="ContentType">ポストするコンテンツタイプ</param>
public Streams OpenUploadStreams(string Url, ContentType ContentType = ContentType.None)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.Method = "POST";
request.ContentType = ContentType.ToKey();
request.CookieContainer = CookieContainer;
return new Streams(
new StreamData[]
{
new StreamData()
{
StreamType = StreamType.Write,
GetStream = () => new Task<ConnectionStream>(() =>
{
return new ConnectionStream()
{
Stream = request.GetRequestStreamAsync().Result,
};
}),
},
new StreamData()
{
StreamType = StreamType.Read,
GetStream = () => new Task<ConnectionStream>(() =>
{
var response = request.GetResponseAsync().Result;
return new ConnectionStream()
{
Stream = response.GetResponseStream(),
Size = response.ContentLength,
};
}),
},
});
}
示例2: Upload
/// <summary>データのアップロード</summary>
/// <param name="Url">アップロードURL</param>
/// <param name="Data">アップロードデータ</param>
/// <param name="ContentType">ポストするコンテンツタイプ</param>
public byte[] Upload(string Url, byte[] Data, ContentType ContentType = ContentType.None)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.Method = "POST";
request.ContentType = ContentType.ToKey();
request.CookieContainer = CookieContainer;
//アップロード
using (var requestStream = request.GetRequestStreamAsync().Result)
requestStream.Write(Data, 0, Data.Length);
//レスポンス取得
using (var response = request.GetResponseAsync().Result.GetResponseStream())
using (var memoryStream = new MemoryStream())
{
response.CopyTo(memoryStream);
return memoryStream.ToArray();
}
}