我正在尝试使用servicerunner编写ServiceStack Web服务的Raw数据。这适用于SOAP请求,但对于REST请求,GetRawBody()返回空。
public override void BeforeEachRequest(IRequest requestContext, T request)
{
Logger.Write(requestContext.GetRawBody());
}
答案 0 :(得分:1)
默认情况下,Web服务器仅提供仅向前的请求流,您可以告诉ServiceStack跳过反序列化,以便您可以通过implementing IRequiresRequestStream on your Request DTO读取请求流:
public class MyRequest : IRequiresRequestStream
{
Stream RequestStream { get; set; }
}
将注入请求流而不是反序列化请求DTO,例如:
public class object Any(MyRequest request)
{
var requestBody = request.RequestStream.ReadFully().FromUtf8Bytes();
}
否则,如果您希望ServiceStack反序列化请求,并且您希望稍后从请求主体重新读取,则需要使用预请求过滤器告诉ServiceStack buffer the Request:
appHost.PreRequestFilters.Add((httpReq, httpRes) => {
httpReq.UseBufferedStream = true;
});