How to consume HttpClient from F#?

后端 未结 5 1786
攒了一身酷
攒了一身酷 2021-02-20 04:13

I\'m new to F# and stuck in understanding async in F# from the perspective of a C# developer. Say having the following snippet in C#:



        
5条回答
  •  一整个雨季
    2021-02-20 05:13

    Just use FSharp.Control.FusionTasks and you will have clear syntax without |> Async.AwaitTask like

       let httpClient = new System.Net.Http.HttpClient ()
    
       let getAsync (url:string) = 
        async {
            let! response = httpClient.GetAsync url
            response.EnsureSuccessStatusCode () |> ignore
            let! content = response.Content.ReadAsStringAsync ()
            return content
        }
    

提交回复
热议问题