xcode iPhone 的 HTTP 身份验证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1420489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTTP Authentication for iPhone
提问by maddy
Probably Duplicate of
可能是重复的
i want to write an http authentication program for iphone. should i do it using soap request or NSURLConnection?
我想为 iphone 编写一个 http 身份验证程序。我应该使用soap请求还是NSURLConnection?
Please give me one good link where i can get help how to do it step by step ,
请给我一个好的链接,我可以在那里获得帮助,如何一步一步地做到这一点,
Regards,
问候,
回答by Andiih
NSMutableURLRequest is probably most flexible for this sort of work. Take a look at the solution here Google App Engine with ClientLogin Interface for Objective-C
NSMutableURLRequest 对于这类工作可能是最灵活的。看看这里的解决方案Google App Engine with ClientLogin Interface for Objective-C
If that doesn't help can you clarify your question please.
如果这没有帮助,请您澄清一下您的问题。
回答by Hyman Cox
Maddy,
麦迪,
The Apple docs on NSURLConnection (http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html) have a good section on handling authentication requests.
NSURLConnection 上的 Apple 文档(http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html)有一个关于处理身份验证请求的很好的部分。
What you'll need to do is use the async mode of NSURLConnection and define a delegate for the connection that has an appropriate didReceiveAuthenticationChallenge: method in the delegate. This method will be called if the HTTP server demands authentication. There are classes in the SDK that assist with building the BASIC authentication response for this method and I believe that the aforementioned URL has some example code within that documentation.
您需要做的是使用 NSURLConnection 的异步模式并为连接定义一个委托,该委托在委托中具有适当的 didReceiveAuthenticationChallenge: 方法。如果 HTTP 服务器要求身份验证,将调用此方法。SDK 中有一些类可以帮助构建此方法的 BASIC 身份验证响应,我相信上述 URL 在该文档中包含一些示例代码。
Hyman
Hyman