2011-08-11 32 views
0

我試圖使用ASP.NET C#HttpRequest的....我使用Firebug和調試登錄地址,發現登錄到Flash網站:http://sechiakhoanhkhac.com/live/data.php?mod=member&act=login登錄Flash網站使用的HttpRequest

和我的代碼在這裏:

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(); 

//做登錄

代碼是錯誤的或右後出頭?因爲我不能登錄,不知道我什麼時候登錄或不...因爲這是Flash網站,所以我們可以得到響應檢查...

回答

0

Web服務需要設置「Referer」字段,例如:

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

然後服務將返回在消息正文中下列反應(這似乎是用戶名和ID):

sangdeptrai,46104 

附加信息:我用Fiddler檢查請求和響應同時登錄。完整的請求如下所示:

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 

解壓的反應是這樣的:

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

咱們我試試........... –

+0

它的工作:) –