简体   繁体   English

ServiceStack:原始请求流

[英]ServiceStack: Raw Request Stream

I attempting to read the raw input stream in a ServiceStack Service. 我试图读取ServiceStack服务中的原始输入流。 I have marked the DTO with IRequiresRequestStream , and the code to read executes, but the content always shows as blank. 我已经用IRequiresRequestStream标记了DTO,并且读取的代码已执行,但是内容始终显示为空白。

Using debug mode in IE9, I can see the raw HttpRequest contains text within the POST as delivered. 在IE9中使用调试模式,我可以看到原始的HttpRequest包含已交付的POST中的文本。

Here is my code from a minimal test service intended only to show reading of the content and query: 这是我来自最小测试服务的代码,仅用于显示内容的读取和查询:

[Route("/qtest")]
public class QueryTestRequest : IReturn<string>, IRequiresRequestStream
{
    public Stream RequestStream { get; set; }
}

public class QueryTestService : Service
{
    public string Any(QueryTestRequest request)
    {
        var r = new StringBuilder(); 
        r.Append("<p>This is the query test service:");

        r.AppendFormat("<p>Parameter value={0}", base.Request.QueryString["value"]);

        var postStream = new StreamReader(request.RequestStream);
        var postContent = postStream.ReadToEnd();           

        r.AppendFormat("<p>Raw Content={0}", postContent);

        return r.ToString();
    }
}

What am I missing here? 我在这里想念什么?

Yes I find that weird as well, but maybe it's me who doesn't understand the nature of the HttpRequestStream. 是的,我也觉得很奇怪,但是也许是我不理解HttpRequestStream的本质。

Anyway... I managed to get hold of the file using: 无论如何...我设法使用以下方法来保存文件:

var stream = Request.Files[0].InputStream;

And then you can handle that stream. 然后您可以处理该流。

It appears that more than one file can be uploaded, but I guess that would be difficult to wrap into a REST-framework. 看来可以上传多个文件,但是我想很难将其包装成REST框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM