如何设置 Suave 以访问任何路由上的 post 消息,并绑定到“*”

how to set up Suave to access a post message on any route, and binding to "*"

我需要设置一项服务,该服务需要接受 POST 消息到该 IP 上的任何路由,并让网络服务器监听机器拥有的所有 IP

我可以轻松地列出本地IP列表,将127.0.0.1添加到其中进行测试。

如何在任何 post 请求上设置回传内容?我 1 小时前才开始看它,所以答案可能很明显。

这将处理发送到您想要的任何绑定的所有 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 测试:Invoke-WebRequest -uri "http://127.0.0.1:8081/Hello" -Method POST

输出:POST received: /Hello