Befehl per Post an AV-Receiver senden

  • Hallo zusammen,

    ich möchte folgenden String an meinen AV-Receiver per Post senden:

    Code
    '<YAMAHA_AV cmd="PUT"><Main_Zone><Volume><Lvl><Val>Up</Val><Exp></Exp><Unit></Unit></Lvl></Volume></Main_Zone></YAMAHA_AV>'

    Ich habe es schon per TCPSend probiert aber leider kann ich so nicht die Antwort des Receivers empfangen. Gibt es eine UDF mit deren Hilfe ich einfach einen Header + Post-Befehl an eine IPAdresse senden kann und dann auch die Antwort bekomme?
    Danke schonmal für eure Hilfe :)

  • Danke für die schnelle Antwort. Ich hab das jetzt mal ganz schnell ausprobiert aber leider bekomme ich weder eine Antwort, noch kommt der Befehl an.
    Kann da mal jemand ein Auge drauf werfen, ich sehe jetzt auf den ersten Blick leider keinen Fehler:

    [autoit]


    #include "WinHttp.au3"

    [/autoit][autoit][/autoit][autoit]

    $host = "192.168.178.18"
    $data = '<YAMAHA_AV cmd="PUT"><Main_Zone><Volume><Lvl><Val>Up</Val><Exp></Exp><Unit></Unit></Lvl></Volume></Main_Zone></YAMAHA_AV>'
    ;=============HEADER=============
    ;~ $command_lenght = StringLen($data)

    [/autoit][autoit][/autoit][autoit]

    ;~ $head = ""
    ;~ $head &= "POST /YamahaRemoteControl/ctrl HTTP/1.1" & @CRLF
    ;~ $head &= "Host " & $host & @CRLF
    ;~ $head &= "User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv12.0) Gecko/20100101 Firefox/12.0" & @CRLF
    ;~ $head &= "Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" & @CRLF
    ;~ $head &= "Accept-Language de-de,de;q=0.8,en-us;q=0.5,en;q=0.3" & @CRLF
    ;~ $head &= "Accept-Encoding gzip, deflate" & @CRLF
    ;~ $head &= "Connection keep-alive" & @CRLF
    ;~ $head &= "Content-Type text/xml; charset=UTF-8" & @CRLF
    ;~ $head &= "Referer http;" & $host & "/" & @CRLF
    ;~ $head &= "Content-Length " & $command_lenght & @CRLF
    ;~ $head &= "Pragma no-cache" & @CRLF
    ;~ $head &= "Cache-Control no-cache" & @CRLF & @CRLF
    ;~ $head &= $data

    [/autoit][autoit][/autoit][autoit]

    ; Initialize and get session handle
    Global $hOpen = _WinHttpOpen("Mozilla/5.0 (Windows NT 6.1; WOW64; rv12.0) Gecko/20100101 Firefox/12.0")

    [/autoit][autoit][/autoit][autoit]

    ; Get connection handle
    Global $hConnect = _WinHttpConnect($hOpen, $host)

    [/autoit][autoit][/autoit][autoit]

    ; Make a request
    Global $hRequest = _WinHttpOpenRequest($hConnect, "POST")

    [/autoit][autoit][/autoit][autoit]

    ; Send it. Specify additional data to send too. This is required by the Google API:
    _WinHttpSendRequest($hRequest, "Content-Type text/xml", $data)

    [/autoit][autoit][/autoit][autoit]

    ; Wait for the response
    _WinHttpReceiveResponse($hRequest)

    [/autoit][autoit][/autoit][autoit]

    ; See what's returned
    Global $sReturned
    If _WinHttpQueryDataAvailable($hRequest) Then ; if there is data
    Do
    $sReturned &= _WinHttpReadData($hRequest)
    Until @error
    EndIf

    [/autoit][autoit][/autoit][autoit]

    ; Close handles
    _WinHttpCloseHandle($hRequest)
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)

    [/autoit][autoit][/autoit][autoit]

    ; See what's returned
    MsgBox(0, "Returned", $sReturned)

    [/autoit]

    Ich hab oben auch mal den Header mit angefügt, vielleicht hab ich auch einfach nur was übersehen.

  • Versuch es mal so:

    Spoiler anzeigen
    [autoit]

    #include "WinHttp.au3"

    [/autoit] [autoit][/autoit] [autoit]

    $host = "192.168.178.18"
    $data = '<YAMAHA_AV cmd="PUT"><Main_Zone><Volume><Lvl><Val>Up</Val><Exp></Exp><Unit></Unit></Lvl></Volume></Main_Zone></YAMAHA_AV>'
    ;=============HEADER=============
    ;~ $command_lenght = StringLen($data)

    [/autoit] [autoit][/autoit] [autoit]

    ;~ $head = ""
    ;~ $head &= "POST /YamahaRemoteControl/ctrl HTTP/1.1" & @CRLF
    ;~ $head &= "Host " & $host & @CRLF
    ;~ $head &= "User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv12.0) Gecko/20100101 Firefox/12.0" & @CRLF
    ;~ $head &= "Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" & @CRLF
    ;~ $head &= "Accept-Language de-de,de;q=0.8,en-us;q=0.5,en;q=0.3" & @CRLF
    ;~ $head &= "Accept-Encoding gzip, deflate" & @CRLF
    ;~ $head &= "Connection keep-alive" & @CRLF
    ;~ $head &= "Content-Type text/xml; charset=UTF-8" & @CRLF
    ;~ $head &= "Referer http;" & $host & "/" & @CRLF
    ;~ $head &= "Content-Length " & $command_lenght & @CRLF
    ;~ $head &= "Pragma no-cache" & @CRLF
    ;~ $head &= "Cache-Control no-cache" & @CRLF & @CRLF
    ;~ $head &= $data

    [/autoit] [autoit][/autoit] [autoit]

    ; Initialize and get session handle
    Global $hOpen = _WinHttpOpen("Mozilla/5.0 (Windows NT 6.1; WOW64; rv12.0) Gecko/20100101 Firefox/12.0")

    [/autoit] [autoit][/autoit] [autoit]

    ; Get connection handle
    Global $hConnect = _WinHttpConnect($hOpen, $host)

    [/autoit] [autoit][/autoit] [autoit]

    ; Make a request
    Global $hRequest = _WinHttpOpenRequest($hConnect, "POST", "/YamahaRemoteControl/ctrl") ;Pfad zur Ressource vergessen

    [/autoit] [autoit][/autoit] [autoit]

    ; Send it. Specify additional data to send too. This is required by the Google API:
    _WinHttpSendRequest($hRequest, "Content-Type: text/xml", $data) ;Doppelpunkt bei Header vergessen

    [/autoit] [autoit][/autoit] [autoit]

    ; Wait for the response
    _WinHttpReceiveResponse($hRequest)

    [/autoit] [autoit][/autoit] [autoit]

    ; See what's returned
    Global $sReturned
    If _WinHttpQueryDataAvailable($hRequest) Then ; if there is data
    Do
    $sReturned &= _WinHttpReadData($hRequest)
    Until @error
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; Close handles
    _WinHttpCloseHandle($hRequest)
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)

    [/autoit] [autoit][/autoit] [autoit]

    ; See what's returned
    MsgBox(0, "Returned", $sReturned)

    [/autoit]


    Ich hab die Fehler die mir aufgefallen sind kommentiert.

  • Was in dem Script fehlt sind die Fehlerprüfungen. Jede der _HTTP-Funktionen gibt einen Fehlercode zurück. Der sollte vor der Weiterverarbeitung geprüft werden!

  • Woher hast du den XML-Kram, den du sendest ?
    Wenn du ein funktionierendes Programm hast, das dein Gerät steuert, dann nimm mal
    einen Packetlogger (z.B. Fiddler2) und vergleiche die gesendeten Requests.

    Wer andern eine Bratwurst brät
    der hat ein Bratwurstbratgerät.

  • Danke an alle für die Antworten.

    Versuch es mal so:

    Ich hab die Fehler die mir aufgefallen sind kommentiert.

    Es funktioniert und ich bekomme eine Antwort. Vielen, Vielen Dank :)