【发布时间】:2021-07-19 04:45:26
【问题描述】:
我正在尝试使用 Asyn 调用,但在拆箱结果时遇到问题。这是我得到的错误信息:“System.Threading.Tasks.Task(Of String)”类型的值无法转换为“String”。 有人可以帮助实现这一目标。这是我使用的代码:
Private Sub Download_Click(sender As Object, e As EventArgs) Handles Button1.Click
'GET DOWNLOAD URL
Dim download_url As String = Download_HttpClient(space_id, file_id)
'ACCESS URL THROUGH GOOGLE CHROME
Dim proc As New ProcessStartInfo()
proc.FileName = "C:\Windows\System32\cmd.exe"
proc.Arguments = "/c start chrome " + download_url
Process.Start(proc)
End Sub
Public Async Function Download_HttpClient(ByVal spaceId As String, fileId As String) As Task(Of String)
Dim cookieContainer As New CookieContainer
Dim httpClientHandler As New HttpClientHandler
httpClientHandler.AllowAutoRedirect = True
httpClientHandler.UseCookies = True
httpClientHandler.CookieContainer = cookieContainer
Dim httpClient As New HttpClient(httpClientHandler)
'GET LOGIN CREDENTIALS
Dim login_url As String = host + "/common/Authentication.json"
Dim login_parameter As String = "?id=" + user_id + "&pw=" + password
Dim login_response As HttpResponseMessage = Await httpClient.GetAsync(login_url + login_parameter)
Dim login_contents As String = Await login_response.Content.ReadAsStringAsync()
'MessageBox.Show(login_contents)
'GET DOWNLOAD ID
Dim download_url As String = host + "/contentsmanagement/SingleContentsDownloadApi.json"
Dim download_param As String = "?fileId=" + file_id + "&spaceId=" + space_id + "&type=alive"
Dim download_response As HttpResponseMessage = Await httpClient.GetAsync(download_url + download_param)
Dim download_contents As String = Await download_response.Content.ReadAsStringAsync()
Dim downloadId As String = Nothing
Dim map As Dictionary(Of String, String)
map = JsonConvert.DeserializeObject(Of Dictionary(Of String, String))(download_contents)
map.TryGetValue("id", downloadId)
'MessageBox.Show(downloadId)
'set DOWNLOAD URL
Dim url As String = host + "/contentsmanagement/ContentsDownloadApi.json?id=" + downloadId
Return url
End Function
【问题讨论】:
标签: vb.net