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
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")
2条答案
按热度按时间gwbalxhn1#
使用
System.Net.Http
可以执行以下操作:ql3eal8s2#
并将其作为json存储在变量result中