使用 Obj C 和 Xcode 进行基本 HTTP 身份验证

发布于 2024-08-26 05:01:39 字数 1291 浏览 6 评论 0原文

我希望有人可以帮助我解决与 Xcode 2.3 应用程序中的基本 HTTP 身份验证相关的问题。

基本上我在我们的服务器上有一个 PHP 页面,当使用某些参数调用时会返回与服务器条件等相关的数据。

我已经设法让一个小型 Xcode 应用程序工作,它从页面读取数据并使用以下命令填充 NSTextView数据。

然而,为了确保这些信息的安全,我在页面上设置了基本的 HTTP 身份验证,但我无法弄清楚如何在 XCode 中提供用户名和密码。

这是我检索页面的代码。

NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
NSString *content = [NSString stringWIthContentsOfUrl:url];
[myTextView setString:content];

关于 xcode 和 obj c,我仍处于非常基本的初学者水平,所以我将非常感激关于我如何进行此操作的简单示例。

谢谢 克里斯

好的,根据我在查看有关此问题的网站时收到的初步评论,这里发生的事情是,我浏览了提供的网页,并努力让代码在我的程序中工作。

现在,当我运行我的程序并单击按钮进行登录时,调试窗口会在这一行弹出,

NSString *authHeader = [@"Basic " stringByAppendingFormat:@"%@",   
    [NSString stringWithCString:encodedLoginData length:strlen(encodedLoginData)]]; 

这是在调试日志中,此时

Program loaded.
sharedlibrary apply-load-rules all
Attaching to program: `/Users/kristiaandavies/getWebData/build/Debug/getWebData.app/Contents/MacOS/getWebData', process 982.
Pending breakpoint 1 - ""AppController.m:10" resolved

我单击“继续”尝试进一步操作,然后从调试日志中获取此信息

(gdb) continue
Current language:  auto; currently objective-c
Program received signal:  "EXC_BAD_ACCESS".
(gdb) 

并且程序冻结了???

I am hoping someone can help me with a question i have relating to Basic HTTP Authentication in an Xcode 2.3 application.

Basically i have a PHP page that is on our server and when called with certain parameters returns data relating to the servers condition etc.

i have managed to get a small Xcode application working where by it reads the data from the page and populates an NSTextView with the data.

however to make sure this information stays safe i have setup basic HTTP Authentication on the page, but i cannot work out how to provide the username and password in XCode.

here is my code to retrieve the page.

NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
NSString *content = [NSString stringWIthContentsOfUrl:url];
[myTextView setString:content];

i am still at a very basic beginner level regarding xcode and obj c, so nice simple examples of how i go about this would really be appreciated.

Thanks
Kris

ok following on from the intial comment i got about looking at a website regarding this issue here is whats happened, ive had a look through the webpage supplied and have struggled to get code working in my program.

now when i run my program and click the button to-do the login the debug window pops up on this line

NSString *authHeader = [@"Basic " stringByAppendingFormat:@"%@",   
    [NSString stringWithCString:encodedLoginData length:strlen(encodedLoginData)]]; 

this is in the debug log at this point

Program loaded.
sharedlibrary apply-load-rules all
Attaching to program: `/Users/kristiaandavies/getWebData/build/Debug/getWebData.app/Contents/MacOS/getWebData', process 982.
Pending breakpoint 1 - ""AppController.m:10" resolved

i click continue to attempt to get it going further and then get this from the debug log

(gdb) continue
Current language:  auto; currently objective-c
Program received signal:  "EXC_BAD_ACCESS".
(gdb) 

and the program freezes???

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

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

发布评论

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

评论(1

走过海棠暮 2024-09-02 05:01:39

这是一个可以帮助您开始正确方向的链接。

http://www.chrisumbel.com/article/basic_authentication_iphone_cocoa_touch

Here is a link that may get you started in the right direction.

http://www.chrisumbel.com/article/basic_authentication_iphone_cocoa_touch

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