2012年12月16日 星期日
WPF 呼叫 WEB API 取得回傳的資料
Imports System.Net.Http
Imports System.Net.Http.Headers
Class MainWindow
Dim client As HttpClient = New HttpClient
Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
client.BaseAddress = New Uri("http://localhost:60014")
client.DefaultRequestHeaders.Accept.Add(
New MediaTypeWithQualityHeaderValue("application/json"))
End Sub
Private Async Sub btn1_Click(sender As Object, e As RoutedEventArgs)
Dim response = Await client.GetAsync("api/JB")
response.EnsureSuccessStatusCode()
Dim result As String = Await response.Content.ReadAsStringAsync()
txt1.Text = result
End Sub
End Class
訂閱:
文章 (Atom)