使用 acceptJson 时,土星 API 不响应 GET



当 GET 方法是管道的一部分时,F# Saturn Web 框架在检索 GET 方法的值时失败acceptJson

下面是我运行以重现该问题的示例代码:

let api = pipeline {
plug acceptJson
set_header "x-pipeline-type" "Api"
}
let apiRouter = router {
not_found_handler (setStatusCode 404 >=> text "Api 404")
pipe_through api
get "/test" (text "Hello world")
}
let appRouter = router {
forward "/api" apiRouter
}

然后将appRouter添加到application代码的use_router部分中。

当我发送带有标头的请求时Content-Type:application/json响应是"找不到 404"。但是,如果我从api管道定义中删除plug acceptJson,我会得到正确的响应。

如何让土星与plug acceptJson一起工作?

我怀疑 3615 是对的 - 这似乎类似于我昨天在用头撞墙一周后刚刚解决的问题。我的浏览器对我的应用程序(只是来自"dotnew new Saturn"的直接应用程序(的请求被接受。但是,来自测试方法的对同一 url 的请求返回了 404。它归结为测试请求缺少"接受"标头的事实。当我添加"接受文本/html"时,它起作用了。我从中推断出,如果应用程序找不到将根据请求接受的内容类型,那么它将报告 404。您的情况是一样的 - 您正在尝试返回 Json,但请求不包含"接受应用程序/json",因此它找不到请求将接受的任何页面。

当然,我可能是错的。

最新更新