2013-10-27 151 views
0

我想實現的目標C的代碼:的HTTPRequest爲論壇登錄 - 目標C

Public Shared Function Login(ByVal Username As String, ByVal Password As String) As Boolean 
    Dim str As String = Func.ConvertToHex(Username) 
    Http.GetResponse("http://www.website.com/forum/login.php?do=login", String.Concat(New String() { "vb_login_username=", str, "&vb_login_password=", Password, "&cookieuser=1&s=&securitytoken=guest&do=login&vb_login_md5password=&vb_login_md5password_utf=" })) 
    If Http.ResponseValue.Contains(("Thank you for logging in, " & Username)) Then 
     Http.GetResponse("http://www.website.com/forum/usercp.php") 
     Return True 
    End If 
    Return False 
End Function 

這是我已經做了:

- (IBAction)loginButton:(id)sender { 
    NSURL *loginURL = [NSURL URLWithString:@"http://www.website.com/forum/login.php?do=login"]; 
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:loginURL]; 
    [request setRequestMethod:@"POST"]; 
    [request setUseKeychainPersistence:YES]; 

    [request addPostValue:[self.usernameField stringValue] forKey:@"vb_login_username="]; 
    [request addPostValue:[self.passwordField stringValue] forKey:@"&vb_login_password="]; 

    [request setDelegate:self]; 
    [request setTimeOutSeconds:60]; 
    [request startSynchronous]; 
    [request setUseSessionPersistence:YES]; 
} 

- (void)requestFailed:(ASIHTTPRequest *)request { 
    NSLog(@"Request failed: %@",[request error]); 
} 

- (void)requestFinished:(ASIHTTPRequest *)request 
{ 
    NSLog(@"Submitted form successfully"); 
    NSLog(@"Response was:"); 
    NSLog(@"%@",[request responseString]); 
} 

但它不工作。 。 我收到回覆,但不是會員。

P.S.這是關於一個vBulletin論壇 對不起,我的英語不好..

在此先感謝!

回答

0

很難嘗試重現而沒有服務器來測試。但兩件事情:

  1. 的lib您使用的折舊,可以考慮在第二個參數移動爲其他(例如AFNetworking)

  2. 你有「& vb_login_password =」我相信應該沒有「& '字符。也試着在結束時刪除'='。

如果沒有HTTPS,您可以使用wireshark從程序中檢查數據包以及您的版本。然後比較兩個請求並尋求差異。

0

它現在的作品。我添加了更多條目。

[request addPostValue:@"1" forKey:@"cookieuser"]; 
[request addPostValue:@"login" forKey:@"do"]; 
[request addPostValue:@"" forKey:@"s"]; 
[request addPostValue:@"guest" forKey:@"securitytoken"]; 
[request addPostValue:@"" forKey:@"vb_login_md5password"]; 
[request addPostValue:@"" forKey:@"vb_login_md5password_utf"]; 
[request addPostValue:[self.passwordField stringValue] forKey:@"vb_login_password"]; 
[request addPostValue:[self.usernameField stringValue] forKey:@"vb_login_username"]; 

我現在從論壇獲取HTML代碼回到「感謝您登錄,用戶名」的地步。