Winhttp - Probleme beim Login

05/20/2013 11:32 cryp0r#1
Hallo,
ich habe schon gesucht wie ein wilder und auch Google bemüht, bin aber zu keiner sinnvollen Lösung für mein Problem gekommen. Darum erhoffe ich mir jetzt Abhilfe. Ich habe angefangen, mich mit der Winhttp.au3 auseinander zu setzen und wollte mich anhand eines Bsps. etwas einarbeiten. Da lag natürlich nahe, bei einem Browsergame einen Login vorzunehmen und dann diverse Daten auf der Seite auszulesen. Vorweg, das soll kein sinnloser Clickbot oder irgendwas in diese Richtung werden. Der Login funktioniert schonmal allerdings weiß ich dann nicht weiter. Wenn ich den Login abschicke, wird auf eine Seite weitergeleitet, auf der man einen Link anklicken müsste um ins Spiel zu kommen, oder man wartet auf die automatische Weiterleitung. Dabei wird ein "Key" erzeugt, welchen ich auch noch auslesen kann. Wenn ich nun aber die eigentliche Spielseite aufrufen möchte und den Quellcode auslese, bekomme ich ein leeres Ergebniss zurück.

Hier nun erstmal mein Code:
Code:
#include <WinHTTP.au3>
#include <String.au3>

Global $pkey
$host_url =  "www.anno1777.com"
$username="********"
$pw="********l"

; Einloggen

$hw_open = _WinHttpOpen("Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5")
$hw_connect = _WinHttpConnect($hw_open, $host_url)

While 1
    _Login()
	_Mainpage()
	;MsgBox(4096, "Test", $pkey[0], 5)
    Exit
WEnd

;_WinHttpCloseHandle($h_openRequest)
_WinHttpCloseHandle($hw_connect)
_WinHttpCloseHandle($hw_open)

func _Login()
	$post="user="&$username&"&pass="&$pw
	$h_openRequest = _WinHttpOpenRequest($hw_connect,"POST", "/pages/index/get_page.php?act=login","HTTP/1.1",$host_url)
	_WinHttpSendRequest($h_openRequest, "Content-Type: application/x-www-form-urlencoded"& @CRLF, $post)
	_WinHttpReceiveResponse($h_openRequest)
	$shtml = _WinHttpReadData($h_openRequest)
	;MsgBox(4096, "Test", $shtml, 10)
	$pkey = _StringBetween($shtml, 'php?key=', '&lang=')
	;MsgBox(4096, "Test", $pkey[0], 5)
	_WinHttpCloseHandle($h_openRequest)
EndFunc

func _Mainpage()
	$post2="key="&$pkey[0]&"&lang=EN"
	;MsgBox(4096, "Test", $post2, 5)
	$h_openRequest = _WinHttpOpenRequest($hw_connect,"POST", "/pages/main/main.php","HTTP/1.1",$host_url)
	_WinHttpSendRequest($h_openRequest, "Referer: http://www.anno1777.com/index.php?lang=EN"& @CRLF &"Content-Type: application/x-www-form-urlencoded"& @CRLF, $post2)
	_WinHttpReceiveResponse($h_openRequest)
	Local $data=""
	Do
		$data&=_WinHttpReadData($h_openRequest)
	Until @error
	MsgBox(0, "Inhalt", $data)
	_WinHttpCloseHandle($h_openRequest)
EndFunc
Der entsprechende Teil aus LiveHttPHeaders sieht so aus:
Code:
http://anno1777.com/pages/index/get_page.php?act=login&user=********&pass=********

GET /pages/index/get_page.php?act=login&user=********&pass=******* HTTP/1.1
Host: anno1777.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://anno1777.com/
Cookie: __utma=220913736.110700815.1368946741.1368993658.1369041945.8; __utmz=220913736.1368946741.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=04ac475bd278d9e2519620f42432b8d6; __utmb=220913736.4.10.1369041945; __utmc=220913736

HTTP/1.1 200 OK
Date: Mon, 20 May 2013 09:28:04 GMT
Server: Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 mod_qos/10.10 PHP/5.4.11
X-Powered-By: PHP/5.4.11
Content-Length: 821
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
----------------------------------------------------------
http://anno1777.com/pages/main/main.php?key=4316979731b0738b6e1831e4be1fcda6&lang=EN

GET /pages/main/main.php?key=4316979731b0738b6e1831e4be1fcda6&lang=EN HTTP/1.1
Host: anno1777.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://anno1777.com/
Cookie: __utma=220913736.110700815.1368946741.1368993658.1369041945.8; __utmz=220913736.1368946741.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=04ac475bd278d9e2519620f42432b8d6; __utmb=220913736.4.10.1369041945; __utmc=220913736

HTTP/1.1 200 OK
Date: Mon, 20 May 2013 09:28:04 GMT
Server: Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 mod_qos/10.10 PHP/5.4.11
X-Powered-By: PHP/5.4.11
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
----------------------------------------------------------
05/20/2013 19:49 Achat#2
_WinHttpSimpleRequest kann ich dir empfehlen.

Und hier meine Funktion:

[Only registered and activated users can see links. Click Here To Register...]

MfG
06/02/2013 11:04 cryp0r#3
Herzlichen Dank für eure unterstützung. Das funktioniert wunderbar. Nun hab ich aber schon das nächste Problem. Ich möchte, das das Script zwischen diversen Zeiten eine Funktion nicht ausführt. Also quasi als Beispiel soll die Funktion _Login() nicht zwischen 8 und 12 Uhr ausgeführt werden. Irgendwie hab ich da nen Hänger und komm auch nicht weiter. Aber evtl. könnt ihr mir mal wieder helfen.

//Edit: Problem selbst gelöst!
06/07/2013 19:28 cryp0r#4
Kaum hat man das eine Problem gelöst, tut sich die nächste Wissenslücke auf. Vielleicht hat hier ja wer ne Idee.

Wie kann ich das mit Winhttp verwirklichen?

Header:
Code:
http://anno1777.com/pages/fin_markets/main.php?key=4f0e28389a756f844ed158544822a2d1&lang=EN&page=forex&sub_page=goldmon&act=buy&sub_item=2&moneda=GLD

POST /pages/fin_markets/main.php?key=4f0e28389a756f844ed158544822a2d1&lang=EN&page=forex&sub_page=goldmon&act=buy&sub_item=2&moneda=GLD HTTP/1.1
Host: anno1777.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://anno1777.com/pages/fin_markets/main.php?key=4f0e28389a756f844ed158544822a2d1&lang=EN&page=forex&sub_page=goldmon&sub_item=2
Cookie: __utma=220913736.110700815.1368946741.1369824826.1370486741.20; __utmz=220913736.1368946741.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=04ac475bd278d9e2519620f42432b8d6; __utmb=220913736.4.10.1370486741; __utmc=220913736; wcsid=IqG1PO05kX0f0VpCL3wnDNKsJ2JFJHpK; hblid=lrUcuT1NiE0f0VpCL3wnDNBL4s9L92A1; _oklv=1370486770439%2CIqG1PO05kX0f0VpCL3wnDNKsJ2JFJHpK; olfsk=olfsk28377175234912544; _okbk=cd4%3Dtrue%2Cvi5%3D0%2Cvi4%3D1370486753752%2Cvi3%3Dactive%2Cvi2%3Dfalse%2Cvi1%3Dfalse%2Ccd8%3Dchat%2Ccd6%3D0%2Ccd5%3Daway%2Ccd3%3Dfalse%2Ccd2%3D0%2Ccd1%3D0%2C; _ok=2174-513-10-8410
Content-Type: application/x-www-form-urlencoded
Content-Length: 13
txt_buy_qty=1
HTTP/1.1 200 OK
Date: Thu, 06 Jun 2013 02:46:29 GMT
Server: Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 mod_fcgid/2.3.6
X-Powered-By: PHP/5.3.22
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
----------------------------------------------------------
Ich denke mal, das die entscheidende Zeile die mit dem Inhalt "txt_buy_qty=1" ist.

Die betreffende Stelle im HTML:
HTML Code:
				  <form id='buy' name='buy' action='main.php?key=4cae6e6d4765dcafa283cf40db200720&lang=EN&page=forex&sub_page=goldmon&act=buy&sub_item=2&moneda=GLD' method='post'>                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="5"><img src="../../global_art/cant_left.gif" width="5" height="34" /></td>
                        <td width="95%" background="../../global_art/cant_middle.gif">
                          <div align="center">
                            <input name="txt_buy_qty" type="text" size="5" maxlength="5" class="cant"/>
                          </div>
                        </td>
                        <td width="5"><img src="../../global_art/cant_right.gif" width="5" height="34" /></td>
                      </tr>
                    </table>
                  </td>
                  <td width="25%">
                            
            <table width="110" border="0" cellspacing="0" cellpadding="0">
              <tr>
              <td width="5"><img id="td_left_56009" width="5" height="34"></td>
              <td align="center" class="text_maro12" id="td_middle_56009" onclick="javascript:document.forms.buy.submit()">Buy GOLD</td>
              <td width="5"><img id="td_right_56009" width="5" height="34"></td>
              </tr> 
            </table>
Ich habs ja schon mit WinHTTPSimpleFormFill probiert, bin aber irgendwie gescheitert. Wahrscheinlich wird durch den mit Javascript erzeugten Button nix abgeschickt.