c#-如何在F#Giraffe Web API中检索URL编码形式?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c#-如何在F#Giraffe Web API中检索URL编码形式?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1651字,纯文字阅读大概需要3分钟。
内容图文
![c#-如何在F#Giraffe Web API中检索URL编码形式?](/upload/InfoBanner/zyjiaocheng/687/78a3fdc9eb3a4fbeb5ac6db227df46e7.jpg)
我正在考虑将C#ASP.NET Core中的WebAPI代码重写为F#Giraffe.
但是,对于某些特定的构造,我真的找不到对等的东西,尤其是对于以下类似的东西:
[HttpPost("DocumentValidationCallbackMessage")]
[Consumes("application/x-www-form-urlencoded")]
public async Task<IActionResult> DocumentValidationCallbackMessage([FromForm] string xml)
{
// Controller Action implementation
}
AFAIK,长颈鹿中的路由不是由控制器提供动力,而是由功能选择:
let webApp =
choose [
GET >=>
choose [
route "/" >=> indexHandler
]
setStatusCode 404 >=> text "Not Found" ]
我真的无法弄清楚如何在F#长颈鹿中解决C#ASP.NET Core属性[Consumes(“ application / x-www-form-urlencoded”)]和[FromForm]的后果:如何直接检索以url编码形式传输的值.
任何想法?
解决方法:
选择只是库中公开的可帮助构建Web应用程序的众多功能之一.我们可以使用许多其他方法来获得与您的样本相同的行为.下面是一个带注释的代码示例,它说明了Giraffe的设计目标,该目标使您可以将功能单元组合到一个自我描述的管道中:
module Sample =
open Giraffe
/// define a type for the model binding to work against.
/// This is the same as saying 'the incoming form will have an string property called xml'
[<CLIMutable>]
type Model =
{ xml: string }
let documentationValidationCallbackMessage: HttpHandler =
route "DocumentValidationCallbackMessage" // routing
>=> POST // http method
>=> bindForm<Model> None (fun { xml = xml } -> // requires the content type to be 'application/x-www-form-urlencoded' and binds the content to the Model type
// now do something with the xml
setStatusCode 200 // in our case we're just going to set a 200 status code
>=> text xml // and write the xml to the response stream
)
这些都可以在documentation处进行更详细地介绍,其中包含许多示例.
希望这可以帮助!
内容总结
以上是互联网集市为您收集整理的c#-如何在F#Giraffe Web API中检索URL编码形式?全部内容,希望文章能够帮你解决c#-如何在F#Giraffe Web API中检索URL编码形式?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。