2012-05-16 44 views
0

我只想在登錄後從頁面中檢索源(字符串)。當我按登錄按鈕時,它給了我第一頁(登錄頁面)的來源。無論我輸入正確還是錯誤的密碼,結果都是一樣的。您的幫助將不勝感激。解析密碼保護的HTML

' - (IBAction爲)buttonPressed:(ID)發送{

// PERFORM LOGIN 
url = [NSURL URLWithString:@"https://www.page asking username and password/"]; 
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 
[request setRequestMethod:@"POST"]; 
[request setPostValue:userName.text forKey:@"UserID"]; 
[request setPostValue:password.text forKey:@"Password"]; 
[request setDelegate:self]; 

[request setDidFailSelector:@selector(PostFailed:)]; 
[request setDidFinishSelector:@selector(PostFinished:)]; 
[request startSynchronous]; 

}

- (void)PostFailed:(ASIHTTPRequest *)theRequest 
{ 
//notify user 
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error sending request to the server" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
[alert show]; 


} 

- (void)PostFinished:(ASIHTTPRequest *)theRequest 

{
//這裏得到你的帖子的響應數據...

// ATTEMPT TO ACCESS ACCOUNT SUMMARY DATA 
url = [NSURL URLWithString:@"https://www.page after I loged in"]; 
ASIHTTPRequest *mainRequest = [ASIHTTPRequest requestWithURL:url]; 

[theRequest setDelegate:self]; 
[mainRequest startAsynchronous]; 


NSLog(@"Response %d ==> %@", theRequest.responseStatusCode, [theRequest responseString]); 

} `

回答

0

您嘗試使用Cookies來驗證您的網站的可能性最大。 由於您正在進行原始HTTP請求,而不是以您的名義存儲cookie,所以您始終會被重定向到登錄頁面,因爲您始終保持未經身份驗證。

要訪問更多網站,您必須在代碼中實現cookie處理。

+0

我認爲,因爲我沒有實現提交按鈕,這也可能是我的原因。這是HTML閱讀提交按鈕的部分。我試圖實現它,但沒有運氣。你知道哪一個在setPostValue中,哪一個在forKey中?    謝謝! – Benjamen