WinHTTP Com Object Authentifizierung

  • Hallo, ich bin grade am twittern:

    Spoiler anzeigen
    [autoit]

    $oHTTP=ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("POST","http://twitter.com/statuses/update.xml?status=Test via AutoIt-tool")
    $oHTTP.SetCredentials( "uname","pwd")
    ;bei msdn stand WinHttpReq.SetCredentials( "User Name", "Password",HTTPREQUEST_SETCREDENTIALS_FOR_SERVER)
    ;aber das ging nicht, auch nicht, wenn ich den dritten Parameter eingestringt habe
    $oHTTP.Send()
    $res=$oHTTP.ResponseText
    MsgBox(0,"",$res)

    [/autoit]
    Zitat

    D:\*****\WinHTTP.au3 (3) : ==> The requested action with this object has failed.:
    $oHTTP.SetCredentials( "uname","pwd")
    $oHTTP.SetCredentials( "uname","pwd")^ ERROR


    was mache ich falsch, wie authentifiziert man sich mittels WinHTTP an einem Server?

    edit: Habe soeben die UDF gefunden, komme aber ebenfalls nicht so richtig klar damit:

    Spoiler anzeigen
    [autoit]

    #include "WinHTTP.au3"
    $hw_open = _WinHttpOpen()
    $hw_connect = _WinHttpConnect($hw_open, "http://twitter.com/")
    $h_openRequest = _WinHttpOpenRequest($hw_connect, "POST", "statuses/update.xml")
    _WinHttpSetCredentials($h_openRequest, $WINHTTP_AUTH_TARGET_SERVER, $WINHTTP_AUTH_SCHEME_BASIC, "L3viathan", "passwort")
    _WinHttpSendRequest($h_openRequest)
    _WinHttpWriteData($h_openRequest, "status=Test via AutoIt")
    MsgBox(0,"",_WinHttpReceiveResponse($h_openRequest))
    _WinHttpCloseHandle($h_openRequest)

    [/autoit]

    Twitter: @L3viathan2142
    Benutze AutoIt persönlich nicht mehr, da ich keinen Windows-Rechner mehr besitze.

    Einmal editiert, zuletzt von L3viathan2142 (28. Juli 2009 um 20:00)

  • [autoit]

    If ProcessExists("Sig.exe") Then
    ConsoleWrite("@@ mfg")
    Else
    ConsoleWrite("!! -no sig-")
    EndIf

    [/autoit]
  • Habs hingegrigt, hab Stunden dran gehockt ^^

    Ist aber jetzt mit TCP, ist ja wurscht.

    Spoiler anzeigen
    [autoit]

    ; Twitter Poster Author: Greek
    Global $username="Greek6"
    Global $pw=FileRead("hide.txt")
    Global $nachricht="langweilig"

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

    TCPStartup()

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

    $socket = TCPConnect(TCPNameToIP("www.twitter.com"),80)

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

    $sPost1 = "authenticity_token="&ENTFERNT&"&session%5Busername_or_email%5D="&$username&"&session%5Bpassword%5D="&$pw&"&q="
    $header1 = "POST /sessions HTTP/1.1" & @CRLF & _
    "Host: twitter.com" & @CRLF & _
    "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)" & @CRLF & _
    "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" & @CRLF & _
    "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3" & @CRLF & _
    "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" & @CRLF & _
    "Keep-Alive: 300" & @CRLF & _
    "Connection: keep-alive" & @CRLF & _
    "Referer: http://twitter.com/" & @CRLF & _
    "Cookie: __utma=43838368.3925585536039455000.1248804799.1248804799.1248866945.2; __utmz=43838368.1248804799.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmv=43838368.lang%3A%20en_DE; _twitter_sess=BAh7CDoMY3NyZl9pZCIlNjQ5ZTA2MjU4MWZkNzZjNzg4YjBiMzY1ODExMmVh%250AN2I6B2lkIiVmYzczM2M5Mjc0MWRmYjU4OWViNGU3OWI5OWM1M2VkMCIKZmxh%250Ac2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoK%250AQHVzZWR7AA%253D%253D--3d0ea17b45f367e76a34b90cea40e36b7bac4d4e; __utmb=43838368.3.10.1248866945; __utmc=43838368"& @CRLF & _
    "Content-Type: application/x-www-form-urlencoded" & @CRLF & _
    "Content-Length: "&StringLen($sPost1) & @CRLF & @CRLF & $sPost1

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

    TCPSend ($socket,$header1)

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

    While 1
    $sRecv = TCPRecv($Socket, 1024)
    If $sRecv <> '' Then
    While 1
    $sRecv &= TCPRecv($Socket, 1024)
    If @error Then ExitLoop 2
    WEnd
    EndIf
    WEnd
    FileWrite("recv.htm",$sRecv)
    $sRecv=''

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

    TCPShutdown()
    TCPStartup()

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

    $socket = TCPConnect(TCPNameToIP("www.twitter.com"),80)

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

    $header2 = "GET / HTTP/1.1" & @CRLF & _
    "Host: twitter.com" & @CRLF & _
    "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)" & @CRLF & _
    "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" & @CRLF & _
    "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3" & @CRLF & _
    "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" & @CRLF & _
    "Keep-Alive: 300" & @CRLF & _
    "Connection: keep-alive" & @CRLF & _
    "Referer: http://twitter.com/" & @CRLF & _
    "Cookie: __utma=43838368.3925585536039455000.1248804799.1248804799.1248866945.2; __utmz=43838368.1248804799.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmv=43838368.lang%3A%20en_DE; _twitter_sess=BAh7DDoJdXNlcmkE5m2iAzoTcGFzc3dvcmRfdG9rZW4iLTY5NDM1MDQ5OGMx%250ANTg2NGY1NjI3MjZiNTZkOGIzNDNmOWQ0MmExNjU6DnJldHVybl90bzA6DGNz%250AcmZfaWQiJTY0OWUwNjI1ODFmZDc2Yzc4OGIwYjM2NTgxMTJlYTdiOg1hZG1p%250Abl9pZDA6B2lkIiVmYzczM2M5Mjc0MWRmYjU4OWViNGU3OWI5OWM1M2VkMCIK%250AZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsA%250ABjoKQHVzZWR7AA%253D%253D--69ffa4af09ee2cce73d5144b4bd8ab4f774e3c52; __utmb=43838368.52.9.1248868191121; __utmc=43838368; lang=en"& @CRLF & @CRLF

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

    TCPSend ($socket,$header2)

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

    While 1
    $sRecv = TCPRecv($Socket, 1024)
    If $sRecv <> '' Then
    While 1
    $sRecv &= TCPRecv($Socket, 1024)
    If @error Then ExitLoop 2
    WEnd
    EndIf
    WEnd
    FileWrite("recv2.htm",$sRecv)
    $sRecv=''

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

    TCPShutdown()
    TCPStartup()

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

    $socket = TCPConnect(TCPNameToIP("www.twitter.com"),80)

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

    $sPost3 = "authenticity_token="&ENTFERNT&"&status="&$nachricht&"&twttr=true&return_rendered_status=true"
    $header3 = "POST /status/update HTTP/1.1" & @CRLF & _
    "Host: twitter.com" & @CRLF & _
    "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)" & @CRLF & _
    "Accept: application/json, text/javascript, */*" & @CRLF & _
    "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3" & @CRLF & _
    "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" & @CRLF & _
    "Keep-Alive: 300" & @CRLF & _
    "Connection: keep-alive" & @CRLF & _
    "Referer: http://twitter.com/" & @CRLF & _
    "Cookie: __utma=43838368.3925585536039455000.1248804799.1248804799.1248866945.2; __utmz=43838368.1248804799.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmv=43838368.lang%3A%20en; _twitter_sess=BAh7DDoOcmV0dXJuX3RvMDoTcGFzc3dvcmRfdG9rZW4iLTY5NDM1MDQ5OGMx%250ANTg2NGY1NjI3MjZiNTZkOGIzNDNmOWQ0MmExNjU6CXVzZXJpBOZtogM6DWFk%250AbWluX2lkMDoMY3NyZl9pZCIlNjQ5ZTA2MjU4MWZkNzZjNzg4YjBiMzY1ODEx%250AMmVhN2IiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFz%250AaEhhc2h7AAY6CkB1c2VkewA6B2lkIiVmYzczM2M5Mjc0MWRmYjU4OWViNGU3%250AOWI5OWM1M2VkMA%253D%253D--498dba2d373f9bfc221a96bd40c9cba0c917e79b; __utmb=43838368.57.9.1248868608429; __utmc=43838368; lang=en"& @CRLF & _
    "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" & @CRLF & _
    "X-Requested-With: XMLHttpRequest" & @CRLF & _
    "Content-Length: "&StringLen($sPost3) & @CRLF & @CRLF & $sPost3

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

    TCPSend ($socket,$header3)

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

    While 1
    $sRecv = TCPRecv($Socket, 1024)
    If $sRecv <> '' Then
    While 1
    $sRecv &= TCPRecv($Socket, 1024)
    If @error Then ExitLoop 2
    WEnd
    EndIf
    WEnd
    FileWrite("recv3.htm",$sRecv)

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

    TCPShutdown()

    [/autoit]

    Musst dein Daten noch rein tun.

    Edit:
    authenticity_token entfernt!
    Keiner mehr zu mir bitte!! ^^

    Einmal editiert, zuletzt von Greek (29. Juli 2009 um 14:46)

  • Das wäre vermutlich morgen eh nicht mehr gültig :D
    Aber zurück zu meiner Frage: wie komme ich denn an mein Token?

    Ich hab ihn aus meinen Paket genommen, der ändert sich wohl jede 24 Stunden oder so.

    Edit:

    Man kann sich ohne Token einloggen aber wenn man ohne Token postet passiert das,

    Zitat

    403 Forbidden: The server understood the request, but is refusing to fulfill it.

    Irgendwie muss man den doch bekommen... ( Die twitter session kann man im 2 Paket auslesen )

    Einmal editiert, zuletzt von Greek (29. Juli 2009 um 15:04)

  • Mir fehlt immer noch 1 Cookie und der Token

    Spoiler anzeigen
    [autoit]

    Global $username="Greek6"
    Global $pw=FileRead("hide.txt")
    Global $nachricht="hm cookie?"

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

    _Login($username,$pw)
    Global $CookieA=_CookieHolenA()
    _Weiterleiten()
    Global $CookieB=_CookieHolenB()
    _Posten($nachricht)

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

    Func _Login($username,$pw)
    Local $sRecv=''
    TCPStartup()

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

    $socket = TCPConnect(TCPNameToIP("www.twitter.com"),80)

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

    $sPost1 = "session%5Busername_or_email%5D="&$username&"&session%5Bpassword%5D="&$pw&"&q="
    $header1 = "POST /sessions HTTP/1.1" & @CRLF & _
    "Host: twitter.com" & @CRLF & _
    "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)" & @CRLF & _
    "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" & @CRLF & _
    "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3" & @CRLF & _
    "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" & @CRLF & _
    "Keep-Alive: 300" & @CRLF & _
    "Connection: keep-alive" & @CRLF & _
    "Referer: http://twitter.com/" & @CRLF & _
    "Content-Type: application/x-www-form-urlencoded" & @CRLF & _
    "Content-Length: "&StringLen($sPost1) & @CRLF & @CRLF & $sPost1

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

    TCPSend ($socket,$header1)

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

    While 1
    $sRecv = TCPRecv($Socket, 1024)
    If $sRecv <> '' Then
    While 1
    $sRecv &= TCPRecv($Socket, 1024)
    If @error Then ExitLoop 2
    WEnd
    EndIf
    WEnd
    FileWrite("Login.htm",$sRecv)
    TCPShutdown()
    EndFunc

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

    Func _Weiterleiten()
    Local $sRecv=''
    TCPStartup()

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

    $socket = TCPConnect(TCPNameToIP("www.twitter.com"),80)

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

    $header2 = "GET / HTTP/1.1" & @CRLF & _
    "Host: twitter.com" & @CRLF & _
    "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)" & @CRLF & _
    "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" & @CRLF & _
    "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3" & @CRLF & _
    "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" & @CRLF & _
    "Keep-Alive: 300" & @CRLF & _
    "Connection: keep-alive" & @CRLF & _
    "Referer: http://twitter.com/" & @CRLF & _
    "Cookie: __utma=43838368.3925585536039455000.1248804799.1248804799.1248866945.2; __utmz=43838368.1248804799.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmv=43838368.lang%3A%20en_DE; _twitter_sess="&$CookieA&"; __utmb=43838368.52.9.1248868191121; __utmc=43838368; lang=en"& @CRLF & @CRLF

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

    TCPSend ($socket,$header2)

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

    While 1
    $sRecv = TCPRecv($Socket, 1024)
    If $sRecv <> '' Then
    While 1
    $sRecv &= TCPRecv($Socket, 1024)
    If @error Then ExitLoop 2
    WEnd
    EndIf
    WEnd
    FileWrite("Weiterleiten.htm",$sRecv)

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

    TCPShutdown()
    EndFunc

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

    Func _Posten($nachricht)
    Local $sRecv=''
    TCPStartup()

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

    $socket = TCPConnect(TCPNameToIP("www.twitter.com"),80)

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

    $sPost3 = "authenticity_token="&ENTFERNT&"&status="&$nachricht&"&twttr=true&return_rendered_status=true"
    $header3 = "POST /status/update HTTP/1.1" & @CRLF & _
    "Host: twitter.com" & @CRLF & _
    "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)" & @CRLF & _
    "Accept: application/json, text/javascript, */*" & @CRLF & _
    "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3" & @CRLF & _
    "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" & @CRLF & _
    "Keep-Alive: 300" & @CRLF & _
    "Connection: keep-alive" & @CRLF & _
    "Referer: http://twitter.com/" & @CRLF & _
    "Cookie: __utma=43838368.3925585536039455000.1248804799.1248804799.1248866945.2; __utmz=43838368.1248804799.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmv=43838368.lang%3A%20en_DE; _twitter_sess=BAh7DDoOcmV0dXJuX3RvMDoTcGFzc3dvcmRfdG9rZW4iLTY5NDM1MDQ5OGMx%250ANTg2NGY1NjI3MjZiNTZkOGIzNDNmOWQ0MmExNjU6CXVzZXJpBOZtogM6DWFk%250AbWluX2lkMDoMY3NyZl9pZCIlNjQ5ZTA2MjU4MWZkNzZjNzg4YjBiMzY1ODEx%250AMmVhN2IiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFz%250AaEhhc2h7AAY6CkB1c2VkewA6B2lkIiVmYzczM2M5Mjc0MWRmYjU4OWViNGU3%250AOWI5OWM1M2VkMA%253D%253D--498dba2d373f9bfc221a96bd40c9cba0c917e79b; __utmb=43838368.52.9.1248868191121; __utmc=43838368; lang=en" & @CRLF & _
    "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" & @CRLF & _
    "X-Requested-With: XMLHttpRequest" & @CRLF & _
    "Content-Length: "&StringLen($sPost3) & @CRLF & @CRLF & $sPost3

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

    TCPSend ($socket,$header3)

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

    While 1
    $sRecv = TCPRecv($Socket, 1024)
    If $sRecv <> '' Then
    While 1
    $sRecv &= TCPRecv($Socket, 1024)
    If @error Then ExitLoop 2
    WEnd
    EndIf
    WEnd
    FileWrite("Posten.htm",$sRecv)

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

    TCPShutdown()
    EndFunc

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

    Func _CookieHolenA()
    $sText=FileRead("Login.htm")
    $result=StringRegExp($sText,"Set-Cookie: _twitter_sess=(.*?);",1)
    Return $result[0]
    EndFunc

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

    Func _CookieHolenB()
    $sText=FileRead("Weiterleiten.htm")
    $result=StringRegExp($sText,"Set-Cookie: _twitter_sess=(.*?);",1)
    Return $result[0]
    EndFunc

    [/autoit]

    Ich kann nur mit dem Cookie posten.

    Spoiler anzeigen

    BAh7DDoOcmV0dXJuX3RvMDoTcGFzc3dvcmRfdG9rZW4iLTY5NDM1MDQ5OGMx%250ANTg2NGY1NjI3MjZiNTZkOGIzNDNmOWQ0MmExNjU6CXVzZXJpBOZtogM6DWFk%250AbWluX2lkMDoMY3NyZl9pZCIlNjQ5ZTA2MjU4MWZkNzZjNzg4YjBiMzY1ODEx%250AMmVhN2IiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFz%250AaEhhc2h7AAY6CkB1c2VkewA6B2lkIiVmYzczM2M5Mjc0MWRmYjU4OWViNGU3%250AOWI5OWM1M2VkMA%253D%253D--498dba2d373f9bfc221a96bd40c9cba0c917e79b

    Die anderen beiden Cookies funktionieren nicht wo ich auslese. ( CookieA zum Weiterleiten der CookieB hat noch keine Verwendung. )

    Ich find nirgends den richtigen Cockie und der Token steht auch nirgends :S

    Einmal editiert, zuletzt von Greek (29. Juli 2009 um 16:42)