How to consume HttpClient from F#?

后端 未结 5 1784
攒了一身酷
攒了一身酷 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:14

    You can use async:

    let readString (url: Uri) = async {
        let httpClient = new HttpClient();
        let! response = httpClient.GetAsync(url) |> Async.AwaitTask
        response.EnsureSuccessStatusCode() |> ignore
        return! response.Content.ReadAsStringAsync() |> Async.AwaitTask
    }
    

提交回复
热议问题