Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

XML-Inhalt von HTTP GET in XML-Datei speichern

Empfohlene Antworten

Hallo,

ich habe folgendes Problem. Ich habe HTTP GET Befehle die im Browser eine XML Datei zurückgeben.

Den Inhalt der HTTP GET Anfrage möchte ich aber nicht im Browser ansehen, sondern als XML-Datei speichern,

so das ich diese dann weiter verarbeiten kann. Ich habe mir aus dem Netz folgendes VBScript zusammen gebaut.

Doch irgendwie ist die Datei leer. Da ich leider kein Programmierer bin, sehe ich leider den Fehler auch nicht.

Kann mir vlt. jemand helfen?

 

Option Explicit


  Dim FSO, objTextFile, Path, strWebSite


  On Error Resume Next

  'The Website URL

  strWebSite = "meineURL.DE"


    'Getting the current directory Path into a variable

  Path = Replace(Wscript.ScriptFullName, Wscript.ScriptName, "")


    'Calling the HTTP Get and Writing the response into text file

  Set FSO = CreateObject("Scripting.FileSystemObject")    'Creating File System Object for writing the code into the text file

  Set objTextFile = FSO.OpenTextFile(Path & "HTTPGetResponse.txt", 8, True)    'Open the text file

  objTextFile.WriteLine Hget(strWebSite)    'Writing the response into the text file

  objTextFile.Close    'Close the Text File


Function Hget(strURL)

  Dim objHTTP

  Set objHTTP = CreateObject("Microsoft.XMLHTTP")    'Create XML HTTP object for the Get method

  objHTTP.Open "GET", strURL, False    'Opening the HTTP get method

  objHTTP.Send()    'Sending the request

  If Err.Number = 0 And objHTTP.Status = 200 Then    'objHTTP.Status returns the status code of the HTTP Get Request

    Hget = objHTTP.ResponseText    'ResponseText returns the response HTML code in text format

  Else

    Hget = "HTTP Error returned! Error Code = " & objHTTP.Status

  End If

  Set objHTTP = Nothing

End Function    '==> HTTP GET Method

Servus!

Klar ist http nicht gleich https ;)

Hier ein kleines Beispiel, wie man dies realisieren könnte.


Imports System.Net

Imports System.IO


Public Class getDocument

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        ServicePointManager.ServerCertificateValidationCallback = New System.Net.Security.RemoteCertificateValidationCallback(AddressOf AcceptCert)


        Dim hreq As HttpWebRequest = CType(HttpWebRequest.Create("https://deineUrl"), HttpWebRequest)

        Dim hres As HttpWebResponse = CType(hreq.GetResponse(), HttpWebResponse)

        Dim s As Stream = hres.GetResponseStream()

        Dim sr As New StreamReader(s)

        Dim html As String = sr.ReadToEnd()


        sr.Close()

        s.Close()


        File.WriteAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\response.html", html)

    End Sub


    Private Function AcceptCert(ByVal sender As Object, ByVal cert As System.Security.Cryptography.X509Certificates.X509Certificate, _

                                ByVal chain As System.Security.Cryptography.X509Certificates.X509Chain, _

                                ByVal errors As System.Net.Security.SslPolicyErrors) As Boolean

        Return True

    End Function

End Class

Denn mal viel Erfolg!

Bearbeitet von uenetz

  • Autor

Hallo uenetz,

danke für deinen Post. Kann es sein, das der Code für VB.Net ist und nicht für VB-Script?

Ich habe versucht diesen auszuführen, doch leider bekomme ich leider eine Fehlermeldung.

Zeile 5

Zeichen 38

Fehler')' erwartet

Kompilierungsfehler in Microsoft VBScript

Ich habe dann auch mal dort ein ) eingeesetzt doch dann wird es immer schlimmer ;)

  • Autor

Hallo uenetz,

OK, Danke! Ich habe jetzt das spielchen im Visual Studio 2012 Express gebaut und funktioniert auch!

Jetzt wäre es toll, wenn ich an das VBA Programm noch 2 Parameter übergeben kann, mit denen ich angeben

kann welche URL und wohin speichern. Ich finde aber leider nicht die Funktion wie ich Übergabeparameter (meineapp.exe para1 para2) bzw. wie ich diese dann in VBA verwenden kann.

Bearbeitet von IT-Biene

In der Funktion/Methode main fügst Du einen Parameter hinzu, den Du dann auswerten kannst.

Sub Main(args As String())

parameter1 = args(0)

parameter2 = args(1)

Ich denke das sollte helfen.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.