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


C# Response.Write方法代码示例

本文整理汇总了C#中System.Net.Response.Write方法的典型用法代码示例。如果您正苦于以下问题:C# Response.Write方法的具体用法?C# Response.Write怎么用?C# Response.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Response的用法示例。


在下文中一共展示了Response.Write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: App

        public static AppAction App()
        {
            return (env, fault, result) => {
                var request = new Request(env);
                var response = new Response(result);
                if (string.IsNullOrWhiteSpace(request.GET["Url"])) {
                    response.ContentType = "text/html";
                    response
                        .Write("<form>")
                        .Write("Url <input type='text' name='Url' style='width:50%;' value='http://download.microsoft.com/download/f/e/6/fe6eb291-e187-4b06-ad78-bb45d066c30f/6.0.6001.18000.367-KRMSDK_EN.iso'/><br/>")
                        .Write("Save as <input type='text' name='SaveAs' style='width:50%;' value='6.0.6001.18000.367-KRMSDK_EN.iso'/><br/>")
                        .Write("<input type='submit' value='Go'/>")
                        .Write("</form>")
                        .Finish();
                }
                else {
                    // make remote request asynchronously
                    var remoteRequest = WebRequest.Create(request.GET["Url"]);

                    remoteRequest.BeginGetResponse(getResponseResult => fault.Guard(() => {
                        var remoteResponse = (HttpWebResponse)remoteRequest.EndGetResponse(getResponseResult);

                        // pass some response headers along
                        response.Status = (int)remoteResponse.StatusCode;
                        response.ContentType = remoteResponse.ContentType;
                        if (!string.IsNullOrWhiteSpace(request.GET["SaveAs"])) {
                            response.AddHeader("Content-Disposition", "attachment; filename=" + request.GET["SaveAs"]);
                        }

                        // pass response body along
                        var remoteStream = remoteResponse.GetResponseStream();
                        if (remoteStream == null) {
                            response.Finish();
                        }
                        else {
                            var buffer = new byte[4096];
                            response.Finish((next, error, complete) =>
                                Loop.Run((halted, continuation) => error.Guard(() =>
                                    remoteStream.BeginRead(buffer, 0, buffer.Length, streamResult => error.Guard(() => {
                                        var count = remoteStream.EndRead(streamResult);
                                        if (halted()) {
                                            return;
                                        }
                                        if (count <= 0) {
                                            complete();
                                            return;
                                        }
                                        if (!next.InvokeAsync(new ArraySegment<byte>(buffer, 0, count), continuation)) {
                                            continuation();
                                        }
                                    }), null))));
                        }
                    }), null);
                }
            };
        }
开发者ID:loudej,项目名称:taco,代码行数:56,代码来源:ProxyApp.cs


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