You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
4.5 KiB
137 lines
4.5 KiB
Imports System
|
|
Imports System.Collections.Generic
|
|
Imports System.Linq
|
|
Imports System.Text
|
|
Imports System.Threading.Tasks
|
|
Imports System.Net.Http
|
|
Imports System.Net.Http.js
|
|
Imports System.Net.Http.Headers
|
|
|
|
Namespace DPMHttpClient
|
|
|
|
|
|
Public Class DPMhttpClient
|
|
|
|
|
|
Public Class DataStore(Of T)
|
|
Public Property daten As String
|
|
Public Property resultstatus As Boolean
|
|
Public Property resultstatuscode As String
|
|
End Class
|
|
|
|
Public ResponsTask As HttpResponseMessage
|
|
Public RespnsResult As HttpRequestMessage
|
|
Public Results As DataStore(Of Object) = New DataStore(Of Object)()
|
|
Public BaseAPI As String = ""
|
|
|
|
Dim uri As String = ""
|
|
Dim apikey As String = ""
|
|
Dim SecretKey As String = ""
|
|
Sub New()
|
|
Dim db As New clsDB
|
|
apikey = db.Get_Option(100001)
|
|
uri = db.Get_Option(100003)
|
|
SecretKey = db.Get_Option(100002)
|
|
db.Dispose()
|
|
End Sub
|
|
|
|
Public Sub CallService(ByVal api As String, ByVal key As String, ByVal fnkt As String, ByVal daten As Object)
|
|
Dim client As HttpClient = New HttpClient()
|
|
client.BaseAddress = New Uri(uri)
|
|
client.DefaultRequestHeaders.Add("ApiKey", apikey)
|
|
client.DefaultRequestHeaders.Add("SecKey", SecretKey)
|
|
Select Case fnkt
|
|
Case "GET"
|
|
|
|
If key <> "" Then
|
|
api = api & "/" & key
|
|
End If
|
|
|
|
Dim responseTask = client.GetAsync(api)
|
|
responseTask.Wait()
|
|
Dim result = responseTask.Result
|
|
Results.resultstatus = responseTask.Result.IsSuccessStatusCode
|
|
|
|
If result.IsSuccessStatusCode Then
|
|
Dim readTask = result.Content.ReadAsStringAsync()
|
|
readTask.Wait()
|
|
Results.daten = readTask.Result
|
|
Exit Select
|
|
End If
|
|
|
|
Case "PUT"
|
|
|
|
If key <> "" Then
|
|
api = api & "/" & key
|
|
End If
|
|
|
|
|
|
Dim postresponse = client.PostAsJsonAsync(api, daten).Result
|
|
Results.resultstatuscode = postresponse.StatusCode.ToString()
|
|
Case "POST"
|
|
|
|
If key <> "" Then
|
|
api = api & "/" & key
|
|
End If
|
|
|
|
|
|
Dim postresponse = client.PostAsJsonAsync(api, daten).Result
|
|
Results.resultstatuscode = postresponse.StatusCode.ToString()
|
|
|
|
Case "PUT"
|
|
|
|
If key <> "" Then
|
|
api = api & "/" & key
|
|
End If
|
|
|
|
|
|
Dim postresponse = client.PostAsJsonAsync(api, daten).Result
|
|
Results.resultstatuscode = postresponse.StatusCode.ToString()
|
|
Case "DELETE"
|
|
|
|
If key <> "" Then
|
|
api = api & "/" & key
|
|
End If
|
|
|
|
Dim deleteresponse = client.DeleteAsync(api).Result
|
|
Results.resultstatuscode = deleteresponse.StatusCode.ToString()
|
|
Case Else
|
|
End Select
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
'Public Shared Sub CallGet(ByVal apikey As String)
|
|
' Dim client As New HttpClient
|
|
' Dim data As Object
|
|
' client.BaseAddress = New Uri("http://localhost:60464/api/")
|
|
' client.DefaultRequestHeaders.Add("apkikey", apikey)
|
|
' client.GetAsync(data)
|
|
' Dim responseTask = client.GetAsync("student")
|
|
' responseTask.Wait()
|
|
' Dim result = responseTask.Result
|
|
' If result.IsSuccessStatusCode Then
|
|
' Dim readTask = result.Content.ReadAsStringAsync()()
|
|
' readTask.Wait()
|
|
' Dim students = readTask.Result
|
|
' For Each student In students
|
|
' Next
|
|
' End If
|
|
|
|
|
|
' End Sub
|
|
|
|
' Private Shared Sub Main(ByVal args As String())
|
|
' Using client = New HttpClient()
|
|
' client.BaseAddress = New Uri("http://localhost:60464/api/")
|
|
' Dim responseTask = client.GetAsync("student")
|
|
' responseTask.Wait()
|
|
' Dim result = responseTask.Result
|
|
|
|
' End Using
|
|
|
|
' Console.ReadLine()
|
|
' End Sub
|
|
End Class
|
|
End Namespace |