Iam trying to replace some older code to use HttpClient. I susspect that I am missing something basic. Using examples I have the code working when requesting from one URL and from another I get Task Canceled
The only difference is the URL. Can someone point me int he right direction?
I have spent over a day on this, and the below code is the current try, I have done through many different things, in all I have the same issue of data not being returned.
The URLs themselves return data when pasted into Chrome browser, so they are valid.
// Does not work (task canceled)
Private Async Sub Button25_Click(sender As Object, e As EventArgs) Handles Button25.Click
Dim strContent As String = Await GetRequest("https://api.beta.tab.com.au/v1/historical-results-service/QLD/racing/2024-04-22/B/R/races/2")
End Sub
//Works
Private Async Sub Button25_Click(sender As Object, e As EventArgs) Handles Button25.Click
Dim strContent As String = Await GetRequest("https://www.tab.com.au/racing/meetings/today/R")
End Sub
Async Function GetRequest(url As String) As Task(Of String)
Using client As New HttpClient()
Using response As HttpResponseMessage = Await client.GetAsync(url)
Using content As HttpContent = response.Content
Dim myContent As String = Await content.ReadAsStringAsync()
Return myContent
End Using
End Using
End Using
End Function