Probleme mit HTTP Request // CURL

  • VB.NET
  • .NET (FX) 4.0

    Probleme mit HTTP Request // CURL

    Hallo,

    ich möchte gerne einen einfachen HTTP Request zur Umschaltung eines Relais in Visual basic ausführen. Wenn ein Button gedrückt wird soll ein "Curl" Befehl ausgeführt werden. IN CMD funktioniert es, nur in VB nicht.

    Es soll der Befehl: "curl "http://192.168.8.41/state.xml?relayState=2" ausgeführt werden.

    Ich verwende das aktuelle "Visual Studio" und erstelle mri ein projekt mit "Windows Forms App Visual Basic"

    Folgenden Code hab ich, könnte mir hier jemand helfen. Danke.

    VB.NET-Quellcode

    1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    2. Dim p = New Process()
    3. p.StartInfo.UseShellExecute = False
    4. p.StartInfo.CreateNoWindow = True
    5. p.StartInfo.FileName = "curl.exe" ' add path info if needed...
    6. p.StartInfo.Arguments = "-v ""http://192.168.8.41/state.xml?relayState=2"""
    7. p.StartInfo.RedirectStandardOutput = True
    8. p.StartInfo.StandardOutputEncoding = Encoding.ASCII
    9. p.StartInfo.RedirectStandardError = True
    10. p.StartInfo.StandardErrorEncoding = Encoding.ASCII
    11. p.Start()
    12. Dim err = p.StandardError.ReadToEnd
    13. Dim out = p.StandardOutput.ReadToEnd
    14. If Not String.IsNullOrWhiteSpace(err) Then Console.WriteLine($"ERROR: {err}")
    15. Console.WriteLine($"{out}")
    16. End Sub


    CodeTags korrigiert ~VaporiZed

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „VaporiZed“ ()