开发者

Login to Flash Site using httprequest

开发者 https://www.devze.com 2023-03-26 23:26 出处:网络
i\'m trying to login to Flash Site using ASP.NET C# httprequest.... i use Firebug and debug login address and found: http://sechiakhoanhkhac.com/live/data.php?mod=member&act=login

i'm trying to login to Flash Site using ASP.NET C# httprequest.... i use Firebug and debug login address and found: http://sechiakhoanhkhac.com/live/data.php?mod=member&act=login

and my code here:

string UrlDangNhap = "http://sechiakhoanhkhac.com/live/data.php?mod=member&act=login";
            //password=123456&email=dmsang -- password=123456&email=sangdeptrai
            string username="sangdeptrai";
            string strPostDataDangNhap = String.Format("password=123456&email={0}",username);              
            //Create Cookie to keep Login status
            CookieContainer cookies = new CookieContainer();
            HttpWebRequest wrDangNhap = WebRequest.Create(UrlDangNhap) as
            HttpWebRequest;
            wrDangNhap.Method = "POST";
            wrDangNhap.ContentLength = strPostDataDangNhap.Length;
            wrDangNhap.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            wrDangNhap.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1";
            wrDangNhap.ContentType = "application/x-www-form-urlencoded";
            wrDangNhap.KeepAlive = true;
            wrDangNhap.CookieContainer = cookies;

            StreamWriter swDangNhap = new StreamWriter(wrDangNhap.GetRequestStream());
            swDangNhap.Write(strPostDataDangNhap);
            swDangNhap.Close();

// do somethings after login

that code is wrong or right? because i cant login and dont know when i login-开发者_高级运维ed or not... because this is flash site so we can get response to check...


The web service needs the "Referer" field to be set, eg:

wrDangNhap.Referer = "http://sechiakhoanhkhac.com/live/main.swf"

The service will then return the following response in the message body (which appears to be the username and ID):

sangdeptrai,46104

Additional info: I used fiddler to inspect the request and response while logging in. The full request looks like this:

POST http://sechiakhoanhkhac.com/live/data.php?mod=member&act=login HTTP/1.1
Host: sechiakhoanhkhac.com
Connection: keep-alive
Referer: http://sechiakhoanhkhac.com/live/main.swf
Content-Length: 33
Origin: http://sechiakhoanhkhac.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1
content-type: application/x-www-form-urlencoded
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

password=123456&email=sangdeptrai

The decompressed response looks like this:

HTTP/1.1 200 OK
Date: Thu, 11 Aug 2011 08:01:10 GMT
Content-Length: 17
Content-Type: text/html
Expires: Thu, 11 Aug 2011 08:01:10 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Server: Apache/2
X-Powered-By: PHP/5.2.17
Pragma: no-cache
Powered-by: Framework 1.0
Visited: www.phpbasic.com
Vary: Accept-Encoding,User-Agent

sangdeptrai,46104
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号