[英]how to set up Suave to access a post message on any route, and binding to “*”
I need to set up a service that need to accept POST messages to ANY route on that IP and have the web server listening to ALL IPs the machine has我需要设置一个服务,该服务需要接受 POST 消息到该 IP 上的任何路由,并让 web 服务器监听机器拥有的所有 IP
I can make a list of local IPs easily, add 127.0.0.1 to it for testing.我可以很容易地制作一个本地 IP 列表,将 127.0.0.1 添加到其中进行测试。
How can I set up a callback on any post request, with the contents?如何在任何发布请求上设置回调,包括内容? I've just started to look at it 1h ago so the answer may be obvious.我在 1 小时前才开始研究它,所以答案可能很明显。
This will handle all POST requests sent to whatever bindings you'd like:这将处理发送到您想要的任何绑定的所有 POST 请求:
open Suave
open Suave.Filters
open Suave.Operators
open Suave.Successful
[<EntryPoint>]
let main argv =
// list your bindings here
let bindings =
[
"127.0.0.1", 8080
"127.0.0.1", 8081
] |> List.map (fun (addr, port) ->
HttpBinding.createSimple HTTP addr port)
let cfg =
{ defaultConfig with bindings = bindings }
// handle all POST requests
let app =
POST >=> request (fun req ->
OK $"POST received: {req.path}")
startWebServer cfg app
0
Powershell test: Invoke-WebRequest -uri "http://127.0.0.1:8081/Hello" -Method POST
Powershell 测试: Invoke-WebRequest -uri "http://127.0.0.1:8081/Hello" -Method POST
Output: POST received: /Hello
Output: POST received: /Hello
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.