6

我想使用 UIWebView 在我的 iphone 应用程序中打开一些网站。该网站需要用户名和密码,我有这些用户名和密码。

我想知道无论如何我可以在没有任何登录屏幕的情况下在我的 UIWebView 中打开网站吗?我的意思是我已经有了用户名和密码,我可以使用这些信息自动登录网站并在我的 UIWebView iphone 应用程序上显示所需的必要页面吗?

我只想摆脱登录网站,因为用户在打开应用程序时已经输入了登录信息。那是多余的。

任何帮助是极大的赞赏。

谢谢。

4

2 回答 2

2

我发现了以Objective-C方式解决这个问题的方法。我们可以使用 NSURLConnection 来发布表单。

代码:

 NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://mobile.twitter.com/session"]
                                                 cachePolicy:NSURLRequestUseProtocolCachePolicy                                              timeoutInterval:60.0];

[theRequest setHTTPMethod:@"POST"];

NSString *postString = [NSString stringWithFormat:@"authenticity_token=%@&username=%@&password=%@",@"9b670208fd22850ec791",@"urUsername",@"urPWD"];
[theRequest setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];

// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
    // Create the NSMutableData to hold the received data.
    // receivedData is an instance variable declared elsewhere.
    receivedData = [[NSMutableData data] retain];
} else {
    // Inform the user that the connection failed.
}

问我是否需要更多信息。

于 2011-04-11T21:59:35.687 回答
0

如果您自己开发了网站,为什么不创建另一个入口点,使用 ssl 将用户名/密码安全地传递到页面?如果 SSL 不是一个选项,您可以在应用程序中生成一个令牌并传递它。那时根本不需要传递用户名/密码。

于 2011-03-31T20:14:14.867 回答