2012-03-29 153 views
0

我有一個網站,我想從我的iphone登錄到iPhone應用程序我正在做,我遵循ASIHttpRequests網站上的文檔,但所有我從響應字符串得到的是HTML代碼登錄頁面,但我得到一個OK的http代碼,爲什麼會發生這種情況?使用ASIHttpRequest登錄網站

這裏是我的代碼:

-(IBAction)fetchData:(id)sender 
{ 
NSURL *url = [NSURL URLWithString:@"http://www.rssit.site90.com/login.php"]; 
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 
[request shouldPresentCredentialsBeforeChallenge]; 
[request setRequestMethod:@"POST"]; 
[request setPostValue:@"" forKey:@"username"]; 
[request setPostValue:@"" forKey:@"password"]; 
[request setDelegate:self]; 
[request startAsynchronous]; 

//Add finish or failed selector 
[request setDidFinishSelector:@selector(requestLoginFinished:)]; 
[request setDidFailSelector:@selector(requestLoginFailed:)]; 




} 

- (void)requestLoginFinished:(ASIHTTPRequest *)request 
{ 

NSString *yourResponse = [request responseString]; 
NSLog(@"%@", yourResponse); 
} 

回答

0

頁面上的形式做一個GET,而不是一個職位。您的服務器可能不期待POST數據,而是查看查詢字符串參數。更改爲 [NSURL URLWithString:@"http://www.rssit.site90.com/login.php?username=YOURUSERNAME&password=YOURPASSWORD"];

並設置requestMethod爲GET。

+0

這沒有奏效,我應該有什麼在我的PHP? – Huntaz556 2012-03-30 04:13:12