本文整理汇总了C#中HttpRequest.SetKeepAlive方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequest.SetKeepAlive方法的具体用法?C# HttpRequest.SetKeepAlive怎么用?C# HttpRequest.SetKeepAlive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.SetKeepAlive方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Request
public void Request(Uri uri)
{
Console.WriteLine("############################################################");
// request
var request = new HttpRequest(uri);
request.EnableEncoding();
request.SetKeepAlive(true);
Console.Write(request.ToString());
#if USE_BYTES_BODY
using (var subject = new ChunkedHttpResponseObserver())
{
var body = new Subject<IList<Byte>>();
body.Subscribe(x =>
{
Console.WriteLine("body: " + x.Count + " bytes");
}
, ex =>
{
Console.WriteLine(ex);
}
, () =>
{
Console.WriteLine("body end");
});
subject.BodyObservable.Subscribe(body);
bool keepAlive = true;
subject.KeepAliveObservalbe
.Subscribe(x =>
{
// disconnect
keepAlive = x;
});
#else
using (var subject = new HttpRawByteSubject())
{
var body = new Subject<Byte>();
var buffer = new List<Byte>();
body.Subscribe(x =>
{
buffer.Add(x);
}
, ex =>
{
Console.WriteLine(ex);
}
, () =>
{
Console.WriteLine("body: " + buffer.Count + " bytes");
Console.WriteLine("body end");
});
subject.BodyObservable.Subscribe(body);
#endif
// statusline
subject.StatusObservable.Subscribe(x =>
{
Console.WriteLine("status: " + x);
});
// response headers
subject.HeaderObservable.Subscribe(x =>
{
Console.WriteLine(x.Key + ": " + x.Value);
}
, () =>
{
Console.WriteLine();
}
);
////////////////////////////
// connect
////////////////////////////
GetConnection(uri)
.Subscribe(x =>
{
// ready to read
subject.OnNext(x);
// send request
x.SendRequestObservable(request)
.Subscribe(_ =>
{
});
}
, subject.OnError
)
;
// wait...
body.Wait();
if (!keepAlive)
{
Close();
}
//.........这里部分代码省略.........