我已经看过这个example在F#中发帖请求,但我想知道如何使用异步发布请求来做同样的事情
type Authentication =
new() = {}
member this.RequestToken() =
use client = new HttpClient()
client.PostAsync "http://example.com"
printfn "requestToken"
修改
根据评论中的请求提供可比较的C#代码。
var body = "some data";
using (var client = new HttpClient(new HttpClientHandler { UseProxy = false })) {
var response = await client.PostAsync("https://example.com", new StringContent(body, Encoding.UTF8, "application/xml"));
var content = await response.Content.ReadAsStringAsync();
}
答案 0 :(得分:2)
对于F#异步代码,您需要使用async
计算表达式和Async.AwaitTask
将C#的Task<_>
类型转换为F#&#39; s {{1} }。我建议你查阅一些关于F#异步工作流程的文档。
Async<_>