如何直接从UIWebView将登录信息传递到网站,而无需再次登录? [英] How do I pass login information to a website from UIWebView directly without any need of logging in once again?

查看:121
本文介绍了如何直接从UIWebView将登录信息传递到网站,而无需再次登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to open some website in my iphone app using UIWebView. The website requires username and password and I have these username and password.

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

I was wondering is there anyway I can open the website in my UIWebView without any login screen? I mean as I already have the username and password, can I use this information to log in to website automatically and show the required necessary page onto my UIWebView iphone app.

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

I just want to get rid of logging to website as users have already entered the login information when they open the app. Thats redundant.

非常感谢您的帮助.

谢谢.

推荐答案

我发现了一种以Objective-C方式解决此问题的方法.我们可以使用NSURLConnection来发布表单.

I have discovered way to solve this in a Objective-C way. We can use NSURLConnection to post the form.

代码:

 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.
}

如果需要更多信息,请问我.

Ask me if you need more information.

这篇关于如何直接从UIWebView将登录信息传递到网站,而无需再次登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆