我正在编写以下代码以发布到Web API.但是,我得到了编译器错误client.PostAsJsonAsync.错误消息是
Error This expression was expected to have type
Async<'a>
but here has type
Tasks.Task<HttpResponseMessage>
Run Code Online (Sandbox Code Playgroud)
码:
[<CLIMutable>]
type Model = { ..... }
let PostIt params = async {
use client = new HttpClient()
let content = { ..... } // a Model built from params
let! response = client.PostAsJsonAsync("http://...", content) // Error!
return response }
Run Code Online (Sandbox Code Playgroud)
在F#中处理Restful API的最佳方法是什么?我正在使用Fsharp.Data.
看起来你需要使用Async.AwaitTask:
let! response = Async.AwaitTask (client.PostAsJsonAsync("http://...", content))
Run Code Online (Sandbox Code Playgroud)
或使用|>运营商:
let! response = client.PostAsJsonAsync("http://...", content) |> Async.AwaitTask
Run Code Online (Sandbox Code Playgroud)