0

我正在尝试在 Objective 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]);
}

但这不起作用..我得到了回复,但不是会员。

PS这是关于一个vBulletin论坛对不起我的英语不好..

提前致谢!

4

2 回答 2

0

很难尝试在没有服务器进行测试的情况下重现。然而有两件事:

  1. 您使用的 lib 已折旧,请考虑转移到其他库(例如 AFNetworking)

  2. 在第二个参数中你有 "&vb_login_password=" 我相信不应该有 '&' 字符。还要尝试在最后删除“=”。

如果没有 HTTPS,您可以使用 wireshark 检查来自程序的数据包,哪些工作有效,以及您的版本。然后比较两个请求并寻找差异。

于 2013-10-27T19:04:58.017 回答
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 代码,它显示“感谢您登录,用户名”。

于 2013-10-28T12:43:29.917 回答