将URL curl 到vb.net

n7taea2i  于 2022-11-13  发布在  .NET
关注(0)|答案(2)|浏览(228)

嗨,我试图找到一个解决方案,如何实现下面的curl在vb.net:
接受:接受:应用程序/json'

gwbalxhn

gwbalxhn1#

使用System.Net.Http可以执行以下操作:

Private Sub GetBtcPrice()

    Using client As System.Net.Http.HttpClient = New System.Net.Http.HttpClient

        client.DefaultRequestHeaders.Add("accept", "application/json")
        Dim sb As New StringBuilder
        sb.Append("?")
        sb.Append("ids=bitcoin&")
        sb.Append("vs_currencies=usd&")
        sb.Append("include_market_cap=false&")
        sb.Append("include_24hr_vol=false&")
        sb.Append("include_24hr_change=false&")
        sb.Append("include_last_updated_at=false&")
        sb.Append("precision=full")

        Dim response As HttpResponseMessage = client.GetAsync("https://api.coingecko.com/api/v3/simple/price" & sb.ToString).GetAwaiter().GetResult()
        Dim sResponse As String = response.Content.ReadAsStringAsync().GetAwaiter().GetResult()
        Console.WriteLine("response: " & sResponse)

    End Using

End Sub
ql3eal8s

ql3eal8s2#

Dim webClient As New System.Net.WebClient

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

Dim result As String = webClient.DownloadString("https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd&include_market_cap=false&include_24hr_vol=false&include_24hr_change=false&include_last_updated_at=false&precision=full")

并将其作为json存储在变量result中

相关问题