简体   繁体   English

在 vb.net 中使用 Flurl

[英]Using Flurl in vb.net

How can I use Flurl in VB.NET for GET and POST?如何在 VB.NET 中使用 Flurl 进行 GET 和 POST? I installed the NuGet package and imported Flurl.我安装了 NuGet package 并导入了 Flurl。

How can I translate this C# code to VB?如何将这段 C# 代码翻译成 VB?

var responseString = await "http://www.example.com/recepticle.aspx"
.PostUrlEncodedAsync(new { thing1 = "hello", thing2 = "world" })
.ReceiveString();

First, import the relevant namespace:首先,导入相关命名空间:

Imports Flurl.Http

..and then this should work: ..然后这应该工作:

Dim responseString = Await "http://www.example.com/recepticle.aspx".
    PostUrlEncodedAsync(New With {.thing1 = "hello", .thing2 = "world"}).
    ReceiveString()

Explanation:解释:

In VB.NET, when declaring an anonymous object, you should use New With instead of new .在 VB.NET 中,声明匿名 object 时,应该使用New With而不是new Also, the properties must be preceded by a dot .此外,属性前面必须有一个点. . .

When breaking statements into multiple lines, the dot can't be at the beginning of the line so we add it at the end of the previous line.将语句分成多行时,点不能位于行首,因此我们将其添加在上一行的末尾。 If you prefer to start the next line with a dot.如果您喜欢用点开始下一行。 You may end the previous line with the line-continuation character _ like this:您可以像这样以行继续符_结束上一行:

Dim responseString = Await "http://www.example.com/recepticle.aspx" _
    .PostUrlEncodedAsync(New With {.thing1 = "hello", .thing2 = "world"}) _
    .ReceiveString()

For more information, see: Continuing a statement over multiple lines有关详细信息,请参阅: 在多行上继续一个语句

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM