本文整理汇总了C#中IContent.Write方法的典型用法代码示例。如果您正苦于以下问题:C# IContent.Write方法的具体用法?C# IContent.Write怎么用?C# IContent.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContent
的用法示例。
在下文中一共展示了IContent.Write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PostAsync
//.........这里部分代码省略.........
if (webException.Response != null)
{
try
{
responseMessage = GetResponseMessage((HttpWebResponse)webException.Response);
tcs.SetResult(responseMessage);
}
catch (Exception ex)
{
tcs.SetException(ex);
}
//finally
//{
// ((IDisposable)webException.Response).Dispose();
//}
}
else
{
tcs.SetException(new ConnectionException("connection error when transport data with server", webException));
}
return;
}
try
{
//using (var response = (HttpWebResponse)getResponseTask.Result)
//{
// responseMessage = GetResponseMessage(response);
//}
responseMessage = GetResponseMessage((HttpWebResponse)getResponseTask.Result);
}
catch (WebException ex)
{
if (ex.Response != null)
{
responseMessage = GetResponseMessage((HttpWebResponse)ex.Response);
((IDisposable)ex.Response).Dispose();
}
else
{
tcs.SetException(ex);
return;
}
}
tcs.SetResult(responseMessage);
});
};
if (content != null)
{
#if DEBUG && LogDuration
var stopwatch1 = Stopwatch.StartNew();
#endif
var getRequestStreamTask = Task.Factory.FromAsync(request.BeginGetRequestStream, request.EndGetRequestStream, null);
// ReSharper disable once UnusedVariable
var task1 = getRequestStreamTask.ContinueWith(tsk =>
{
#if DEBUG && LogDuration
var duration0 = stopwatch1.GetAndRest();
#endif
if (tsk.Exception != null)
{
tcs.SetException(tsk.Exception);
return;
}
var requestStream = tsk.Result;
//var bytes = postData;
try
{
content.Write(requestStream);
//requestStream.Write(bytes, 0, bytes.Length);
requestStream.Dispose();
#if DEBUG && LogDuration
var duration1 = stopwatch1.GetAndRest();
#endif
}
catch (Exception ex)
{
tcs.SetException(ex);
return;
}
setp2();
});
}
else
{
setp2();
}
return tcs.Task;
}