当前位置: 首页>>代码示例>>C#>>正文


C# HttpRequest.SetKeepAlive方法代码示例

本文整理汇总了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();
                }
//.........这里部分代码省略.........
开发者ID:ousttrue,项目名称:ReactiveWeb,代码行数:101,代码来源:Program.cs


注:本文中的HttpRequest.SetKeepAlive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。