我可以用我的iPhone应用程序登录我的网站吗?

时间:2022-11-29 23:25:47

I'm trying to make a log in or sign up feature for my web site in my iPhone app. My website is a content management system, and like any other CMS, it has log in and registration features. It also has permmissions, dependent on the user account. I think I would have to use UIWebView for this.

我正在尝试在我的iPhone应用中为我的网站做一个登录或注册功能。我的网站是一个内容管理系统,和其他任何CMS一样,它有登录和注册功能。它还具有基于用户帐户的permmission。我想我需要使用UIWebView。

Are there any examples or tutorials I can examine?

有什么例子或教程我可以检查吗?

1 个解决方案

#1


0  

Check out the documentation for NSURLRequest (and NSMutableURLRequest): you can use it to make a POST request to your login and registration pages, just like a web browser. You can write the form UI in Cocoa/Objective-C and then send the data to the server.

查看NSURLRequest(和NSMutableURLRequest)的文档:可以使用它向登录和注册页面发出POST请求,就像web浏览器一样。您可以使用Cocoa/Objective-C编写表单UI,然后将数据发送到服务器。

As far as displaying the result to the user, you'll have to figure out a way to either parse the returned HTML (bad idea) or modify your CMS to return JSON or XML to iPhone requests (better idea).

就向用户显示结果而言,您必须找到一种方法,要么解析返回的HTML(糟糕的想法),要么修改CMS,将JSON或XML返回给iPhone请求(更好的想法)。

Edit: Here's some sample code, taken from an app I'm working on (it submits data to Last.fm using POST):

这里有一些示例代码,取自我正在开发的一个应用程序(它将数据提交到最后)。调频使用POST):

NSURL *url = [NSURL URLWithString:@"http://example.com/"];
NSString *str = @"This is my example data!";

// everything below here is directly from my app:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[str dataUsingEncoding:NSUTF8StringEncoding]];
[request setValue:kLastFMClientUserAgent forHTTPHeaderField:@"User-Agent"];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
[request setHTTPShouldHandleCookies:NO];

*connection = [[NSURLConnection alloc] initWithRequest:request
                                              delegate:self
                                      startImmediately:YES];

#1


0  

Check out the documentation for NSURLRequest (and NSMutableURLRequest): you can use it to make a POST request to your login and registration pages, just like a web browser. You can write the form UI in Cocoa/Objective-C and then send the data to the server.

查看NSURLRequest(和NSMutableURLRequest)的文档:可以使用它向登录和注册页面发出POST请求,就像web浏览器一样。您可以使用Cocoa/Objective-C编写表单UI,然后将数据发送到服务器。

As far as displaying the result to the user, you'll have to figure out a way to either parse the returned HTML (bad idea) or modify your CMS to return JSON or XML to iPhone requests (better idea).

就向用户显示结果而言,您必须找到一种方法,要么解析返回的HTML(糟糕的想法),要么修改CMS,将JSON或XML返回给iPhone请求(更好的想法)。

Edit: Here's some sample code, taken from an app I'm working on (it submits data to Last.fm using POST):

这里有一些示例代码,取自我正在开发的一个应用程序(它将数据提交到最后)。调频使用POST):

NSURL *url = [NSURL URLWithString:@"http://example.com/"];
NSString *str = @"This is my example data!";

// everything below here is directly from my app:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[str dataUsingEncoding:NSUTF8StringEncoding]];
[request setValue:kLastFMClientUserAgent forHTTPHeaderField:@"User-Agent"];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
[request setHTTPShouldHandleCookies:NO];

*connection = [[NSURLConnection alloc] initWithRequest:request
                                              delegate:self
                                      startImmediately:YES];