我有一個非常簡單的NancyFX模塊,我只是想將回調函數的結果回顯給發件人。轉移編碼爲塊時的空請求體 - NancyFX
我使用的門面將輸入的XML轉換爲JSON,然後將其交給Nancy端點。此外觀正確地將內容更改爲JSON,因爲我可以使用api的echo服務對其進行測試並可以看到響應。
但是,由於facade會刪除content-length頭並將傳輸編碼設置爲chunked,所以Request.Body在我的Nancy模塊中始終爲空。
是否有配置需要在NancyFX中啓用對分塊編碼的支持?
我目前在IIS 7上託管,但也有權訪問IIS 8。
我可以看到使用OWIN託管它可以使用HostConfiguration啓用分塊傳輸,但由於其他因素,我無法使用OWIN託管並依靠IIS託管。
我已經啓用了分塊上IIS與命令傳輸:
appcmd set config /section:asp /enableChunkedEncoding:True
我的web.config目前:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.1" />
<httpHandlers>
<add verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" />
</httpHandlers>
<httpRuntime targetFramework="4.5.1" />
<webServices>
<protocols>
<add name="HttpGet" />
<add name="HttpPost" />
</protocols>
</webServices>
</system.web>
<system.webServer>
<modules>
<remove name="WebDavModule" />
</modules>
<handlers>
<remove name="WebDAV" />
<add name="Nancy" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" />
</handlers>
<validation validateIntegratedModeConfiguration="false" />
<httpErrors existingResponse="PassThrough" />
</system.webServer>
</configuration>
模塊本身是很簡單,包括:
Post["/"] = parameters =>
{
var traceRef = Guid.NewGuid();
var body = this.Request.Body.AsString();
Logger.Trace("Trace ref: {0}, request inbound.", traceRef);
Logger.Trace(body);
AuthRequest auth = new AuthRequest();
try
{
auth = this.Bind<AuthRequest>();
}
catch (Exception ex)
{
Logger.Error("Trace ref: {0}, error: {1}. Exception: {2}", traceRef, ex.Message, ex);
}
var responseObject = new
{
this.Request.Headers,
this.Request.Query,
this.Request.Form,
this.Request.Method,
this.Request.Url,
this.Request.Path,
auth
};
return Response.AsJson(responseObject);
};
謝謝@ Joe-B。我會看看南希的來源。我最終通過消除將JSON轉換爲XML的責任來解決此問題,並讓Nancy模型綁定負責接收和綁定XML或JSON。 –