【问题标题】:Using Flurl in vb.net在 vb.net 中使用 Flurl
【发布时间】:2020-05-15 22:53:10
【问题描述】:
如何在 VB.NET 中使用 Flurl 进行 GET 和 POST?我安装了 NuGet 包并导入了 Flurl。
如何将这段 C# 代码翻译成 VB?
var responseString = await "http://www.example.com/recepticle.aspx"
.PostUrlEncodedAsync(new { thing1 = "hello", thing2 = "world" })
.ReceiveString();
【问题讨论】:
标签:
vb.net
c#-to-vb.net
flurl
【解决方案1】:
首先,导入相关的命名空间:
Imports Flurl.Http
..然后这应该可以工作:
Dim responseString = Await "http://www.example.com/recepticle.aspx".
PostUrlEncodedAsync(New With {.thing1 = "hello", .thing2 = "world"}).
ReceiveString()
解释:
在 VB.NET 中,声明匿名对象时,应使用New With 而不是new。此外,属性前面必须有一个点 .。
将语句分成多行时,点不能位于行首,因此我们将其添加到上一行的末尾。如果您更喜欢用点开始下一行。您可以使用续行符 _ 结束前一行,如下所示:
Dim responseString = Await "http://www.example.com/recepticle.aspx" _
.PostUrlEncodedAsync(New With {.thing1 = "hello", .thing2 = "world"}) _
.ReceiveString()
欲了解更多信息,请参阅:Continuing a statement over multiple lines