VB.net で Web API を取得するためのコード。
1. API 取得用の関数を作成
Private Function WebApiRequest(ByVal targetURL As String) As String
Dim hwreq As HttpWebRequest
hwreq = HttpWebRequest.Create(targetURL)
Dim hwres As HttpWebResponse
hwres = hwreq.GetResponse()
Dim grs As Stream
grs = hwres.GetResponseStream()
Dim sr As StreamReader
sr = New StreamReader(grs)
Dim res As String
res = sr.ReadToEnd()
Return res
hwres.Dispose()
grs.Dispose()
sr.Dispose()
End Function
2. API 取得用の関数を呼び出す
Dim resWebApi As String = WebApiRequest("http://*****")
0 件のコメント:
コメントを投稿