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


C# IResponse.GetBody方法代码示例

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


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

示例1: GetResponseText

        public static string GetResponseText(IResponse response)
        {
            StringBuilder builder = new StringBuilder();

            // Status
            builder.AppendFormat("Status: {0}\n", response.Status);

            // Headers
            foreach (KeyValuePair<string,IEnumerable<string>> header in response.Headers)
                foreach (string value in header.Value)
                builder.AppendFormat("{0}: {1}\n", header.Key, value);

            builder.Append("\n");

            // Body ... just supports a string body for now ... next up: FileInfo support?
            foreach (object bodyPart in response.GetBody())
                if (bodyPart is string)
                    builder.Append(bodyPart as string);
                else if (bodyPart is byte[])
                    throw new NotImplementedException("TODO test CGI byte[] body output"); //builder.Append(Encoding.UTF8.GetString(bodyPart)); // assume UTF8 encoding for now ...
                else if (bodyPart is ArraySegment<byte>)
                    throw new NotImplementedException("TODO test CGI ArraySegment<byte> body output");
                else if (bodyPart is FileInfo)
                    throw new NotImplementedException("TODO test CGI FileInfo body output");
                else
                    throw new FormatException("Unknown object returned by IResponse.GetBody(): " + bodyPart.GetType().Name);

            return builder.ToString();
        }
开发者ID:remitaylor,项目名称:knack,代码行数:29,代码来源:Cgi.cs

示例2: Response

        public Response(IResponse response)
            : this()
        {
            if (response.Status != null)
                Status = response.Status;

            if (response.Headers != null)
                Headers = response.Headers;

            foreach (object o in response.GetBody())
                AddToBody(o);
        }
开发者ID:remitaylor,项目名称:knack,代码行数:12,代码来源:Response.cs

示例3: WriteBody

 private void WriteBody(Stream stream, IResponse response)
 {
     var writer = new StreamWriter(stream);
     foreach(var item in response.GetBody())
     {
         if (item is FileInfo)
         {
             //tbd
         }
         else if(item is byte[])
         {
             var buffer = item as byte[];
             stream.Write(buffer, 0, buffer.Length);
         }
         else if (item is ArraySegment<byte>)
         {
             var buffer = (ArraySegment<byte>) item;
             stream.Write(buffer.Array, 0, buffer.Count);
         }
         else
         {
             var buffer = (string) item;
             writer.Write(buffer);
         }
     }
     writer.Flush();
     stream.Flush();
 }
开发者ID:glennblock,项目名称:knack,代码行数:28,代码来源:Wcf.cs

示例4: ErrorMessagesFor

        public static string[] ErrorMessagesFor(IResponse response)
        {
            List<string> errors = new List<string>();

            // Status
            if (response.Status.IsNull()) errors.Add("Status cannot be null");
            else if (response.Status.IsWhiteSpace()) errors.Add("Status cannot be blank");
            else if (response.Status.ContainsNonASCII()) errors.Add("Status cannot contain non-ASCII characters: " + response.Status);
            else if (response.Status.Contains("\n")) errors.Add("Status cannot include a newline: " + response.Status);
            else if (!Regex.IsMatch(response.Status, @"^\d{3} [\w ]+$"))
                errors.Add("Status must include integer status followed by a space and a reason phrase: " + response.Status);

            // Headers
            if (response.Headers.IsNull()) errors.Add("Headers cannot be null");
            else {
                foreach (KeyValuePair<string, IEnumerable<string>> header in response.Headers) {
                    string key = header.Key;
                    if (key.Contains(" ")) errors.Add("Header keys cannot contain whitespace: " + key);
                    else if (key.Contains(".")) errors.Add("Header keys cannot contain periods: " + key);
                    else if (key.Contains("\n")) errors.Add("Header keys cannot contain newlines: " + key);
                    else if (key.ContainsNonASCII()) errors.Add("Header keys cannot contain non-ASCII characters: " + key);

                    foreach (string value in header.Value)
                        if (value.Contains("\n")) errors.Add("Header values cannot contain newlines: " + key + ": " + value);
                        else if (value.ContainsNonASCII()) errors.Add("Header values cannot contain non-ASCII characters: " + key + ": " + value);
                }
            }

            // Body
            foreach (object bodyPart in response.GetBody())
                if (!SupportedResponseBodyTypes.Contains(bodyPart.GetType()))
                    errors.Add("GetBody() has unsupported type: " + bodyPart.GetType().Name + ".  Supported types: string, byte[], ArraySegment<byte>, FileInfo");
            return errors.ToArray();
        }
开发者ID:remitaylor,项目名称:knack,代码行数:34,代码来源:Lint.cs


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