使用 ASIHTTPRequest 解析 iPhone 的响应

发布于 2024-12-13 13:06:47 字数 874 浏览 0 评论 0原文

我正在尝试通过 iPhone 应用程序使用我的登录凭据访问网站,但 NSLog 仅显示带有登录屏幕的网站...我需要登录屏幕之后的一个。我的代码如下:

- (IBAction)buttonClicked:(id)sender
{
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://webportal.factorforms.com/Portal/Form_Login.aspx"]];

    [request setPostValue:[self.usernameField text] forKey:@"Login1$UserName"];
    [request setPostValue:[self.passwordField text] forKey:@"Login1$Password"];

    [request setDelegate:self];
    [request startAsynchronous];
}

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

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

我的响应只是登录屏幕......我以为我会获得实际登录的 javascript。我不确定我做错了什么。

I'm trying to access a website using my login credentials through an iPhone app but the NSLog just shows the site with the login screen...I need the one AFTER the login screen. My code is as follows:

- (IBAction)buttonClicked:(id)sender
{
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://webportal.factorforms.com/Portal/Form_Login.aspx"]];

    [request setPostValue:[self.usernameField text] forKey:@"Login1$UserName"];
    [request setPostValue:[self.passwordField text] forKey:@"Login1$Password"];

    [request setDelegate:self];
    [request startAsynchronous];
}

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

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

My response is just the log in screen....I thought I would be getting the javascript for my actual login. I'm not sure what I'm doing wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧夏天 2024-12-20 13:06:47

可能您的网站登录后有多个重定向?你也必须解析它。 ASIHttp 可以做到。 [只是意见。]

May be your website after login has multiple redirections? You must parse it too. ASIHttp can do it. [Just opinion.]

独孤求败 2024-12-20 13:06:47

我在尝试与 .NET 站点通信时遇到了类似的问题,并且执行以下操作对我有用:

  1. 包括提交按钮本身的发布值,例如

    [request setPostValue:@"Login" forKey:@"Login1$LoginButton"];

  2. 包括页面视图状态的发布值,因为我认为这可以在某些设置中进行验证:

    NSString *viewState = @"/wEPDwUKMjE0MjI5NDA3Ng9kFgICBA9kFgYCAQ9kFgQCAQ88KwAKAQAPFgIeCFVzZXJOYW1lZWRkAgcPFgIeB1Zpc2libGVoZAIDDxYCHwFoZAIFDxYCHgNzcmMFFkxvZ2luRn JhbWUvRkFDVE9SLmFzcHhkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYBBRdMb2dpbjEkTG9naW5JbWFnZUJ1dHRvbitnh1yDOsbCwQpF6Ic5hi0OUJ4q";

    [request setPostValue:viewState forKey:@"__VIEWSTATE"];

  3. 包含页面事件验证的发布值,因为我认为这可以在某些设置中进行验证:

    NSString *eventValidation = @"/wEWBQL9m8PyDQKUvNa1DwL666vYDAKnz4ybCAKI7MDFB3FJcnRzxnTY+gW6x83FqZF+QS+6";

    [request setPostValue:eventValidation forKey:@"__EVENTVALIDATION";

根据记忆,我将所有这三个问题都放在了问题上,然后我的登录成功了,但我真的应该花时间弄清楚是否需要这三个。

I've run into similar problems when trying to communicate with .NET sites, and doing the following worked for me:

  1. including a post value for the submit button itself, like

    [request setPostValue:@"Login" forKey:@"Login1$LoginButton"];

  2. including a post value for the page's viewstate since I think this can be validated in some setups:

    NSString *viewState = @"/wEPDwUKMjE0MjI5NDA3Ng9kFgICBA9kFgYCAQ9kFgQCAQ88KwAKAQAPFgIeCFVzZXJOYW1lZWRkAgcPFgIeB1Zpc2libGVoZAIDDxYCHwFoZAIFDxYCHgNzcmMFFkxvZ2luRnJhbWUvRkFDVE9SLmFzcHhkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYBBRdMb2dpbjEkTG9naW5JbWFnZUJ1dHRvbitnh1yDOsbCwQpF6Ic5hi0OUJ4q";

    [request setPostValue:viewState forKey:@"__VIEWSTATE"];

  3. include a post value for the page's event validation, since I think this can be validated in some setups:

    NSString *eventValidation = @"/wEWBQL9m8PyDQKUvNa1DwL666vYDAKnz4ybCAKI7MDFB3FJcnRzxnTY+gW6x83FqZF+QS+6";

    [request setPostValue:eventValidation forKey:@"__EVENTVALIDATION";

From memory, I threw all three of these at the problem and my login then succeeded, but I should really have spent the time figuring out if all three were required.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文