Imports VERAG_PROG_ALLGEMEIN.CC015B_TR_EXT_V4_3 Imports VERAG_PROG_ALLGEMEIN.ENS_CC315A Public Class cHMRC_ENS '---> VERAG AG!!! GVMS use 26 86 22 45 50 78? Public Shared ApplicationName = "AVISO_ENS" Public Shared ApplicationID = "af3dc225-6726-4cba-98e6-9b8df39b4c20" Public Shared Client_ID = "Qbwx6C1YYdc6q4XM0aWOKZGH0zyO" Public Shared Client_Secret = "143a33cc-33c8-43bb-bcca-51186ac52855" Public Shared TEST As Boolean = True Shared Function helloWorldENS(ByVal response As String) As Boolean VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat() Dim TOKEN = cHMRC.getTOKEN("ENS_HELLOWORLD") If TOKEN.hasEntry Then ' HTTP-Client initialisieren Dim http As New Chilkat.Http ' HMRC OAuth2 Access Token (muss vorher abgerufen werden) Dim accessToken As String = "YOUR_ACCESS_TOKEN" ' Falls das Token fehlt, Hinweis ausgeben If String.IsNullOrEmpty(accessToken) Then Console.WriteLine("Fehler: Kein OAuth2-Token gefunden!") Return False End If ' Setze die benötigten Header http.SetRequestHeader("Authorization", "Bearer " & accessToken) http.SetRequestHeader("Accept", "application/vnd.hmrc.1.0+json") ' API-Endpunkt für User-Restricted Hello API Dim url As String = "https://test-api.service.hmrc.gov.uk/hello/application" 'Dim url As String = "https://test-api.service.hmrc.gov.uk/hello/user" ' API-Anfrage senden response = http.QuickGetStr(url) ' Fehlerbehandlung If (http.LastMethodSuccess <> True) Then Console.WriteLine("Fehler: " & http.LastErrorText) Else Console.WriteLine("Antwort von HMRC API: " & response) End If Return True End If Return False End Function Shared Function insertENS(ENS_CC315A As CC315AType, ByVal response As String) As Boolean ' Chilkat-Objekt initialisieren Dim http As New Chilkat.Http() ' EORI-Nummer für die Überprüfung 'Dim eoriNumber As String = "GB123456789000" Dim url As String = "" If TEST Then url = "test-api.service.hmrc.gov.uk" Else url = "api.service.hmrc.gov.uk" End If VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat() '------------------------------------------------------- ENS_CC315A = New CC315AType ENS_CC315A.MesSenMES3 = "GB123" ENS_CC315A.DatOfPreMES9 = Now.ToString("yyMMdd") ENS_CC315A.TimOfPreMES10 = Now.ToString("HHmm") ENS_CC315A.MesIdeMES19 = "ABCD1234" 'ENS_CC315A.MesTypMES20 = "CC315A" ENS_CC315A.HEAHEA.RefNumHEA4 = "ABCD1234" ENS_CC315A.HEAHEA.TraModAtBorHEA76 = "4" ENS_CC315A.HEAHEA.TotNumOfIteHEA305 = "1" '------------------------------------------------------- Dim TOKEN = cHMRC.getTOKEN("ENS") If TOKEN.hasEntry Then Dim req As New Chilkat.HttpRequest() ' Setze deine HMRC API-Credentials http.AuthToken = TOKEN.token_BEARER_TOKEN req.HttpVerb = "POST" req.Path = "/customs/imports/declarations" req.ContentType = "application/xml" req.Charset = "utf-8" req.SendCharset = True MsgBox(ENS_CC315A.Serialize) ' Füge das XML als Body hinzu req.LoadBodyFromString(ENS_CC315A.Serialize, "utf-8") ' Füge benötigte Header hinzu req.AddHeader("Accept", "application/x-www-form-urlencoded") '"application/vnd.hmrc.1.0+xml") req.AddHeader("Content-Type", "application/xml; charset=UTF-8") '"application/xml") req.AddHeader("Authorization", "Bearer " & TOKEN.token_BEARER_TOKEN) ' req.AddHeader("Gov-Client-Connection-Method", "WEB_APP_VIA_SERVER") ' req.AddHeader("Gov-Client-Public-IP", "192.168.1.1") ' req.AddHeader("Gov-Client-Timezone", "UTC+00:00") MsgBox(TOKEN.token_BEARER_TOKEN) ' Sende die Anfrage Dim resp As Chilkat.HttpResponse = http.SynchronousRequest(url, 443, True, req) If resp Is Nothing Then Console.WriteLine("Fehler: " & http.LastErrorText) Else Console.WriteLine("Status Code: " & resp.StatusCode) Console.WriteLine("Antwort: " & resp.BodyStr) End If Return True End If Return False End Function End Class