nsurlconnection 服务器需要特殊设置吗?
我想知道服务器是否应该有特殊设置来使用 nsurlconnections?当我尝试创建连接和身份验证时。我没有收到任何错误或警告,但它没有连接。
任何人都可以向我澄清这一点吗?
谢谢
编辑:这是我当前使用的代码
- (void)viewDidLoad {
[super viewDidLoad];
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"loginURl"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
[webView1 scalesPageToFit];
if (theConnection) {
receivedData = [[NSMutableData data] retain];
} else {
NSLog(@"Connection Failed");
}
}
I wanted to know if the server should have special setting to work with nsurlconnections? When I tried creating a connection and authentication. I don't get any error or warning but it does not connected.
Could any one please clarify me on this.
Thanks
Edit: Here is the code I currently use
- (void)viewDidLoad {
[super viewDidLoad];
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"loginURl"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
[webView1 scalesPageToFit];
if (theConnection) {
receivedData = [[NSMutableData data] retain];
} else {
NSLog(@"Connection Failed");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,您的服务器不需要任何特殊配置。
NSURLConnection
仅使用简单的 HTTP 请求。对于身份验证:您需要自己实现身份验证所需的委托方法。另请检查您是否通过 SSL 连接并为此实现所需的委托方法。
编辑:这是我的一个使用 HTTP 身份验证的应用程序的一部分。我发现您还需要在
canAuthenticateAgainstProtectionSpace:
方法中为 NSURLAuthenticationMethodHTTPBasic 返回 YES,否则它将无法工作。No, your server does not need any special config. A
NSURLConnection
uses just simple HTTP-Requests.For the authentication: You need to implement the needed delegate methods for authentication yourself. Also check if you are connectiong through SSL and also implement the required delegate methods for this.
Edit: Heres a piece from one of my Apps that use HTTP auth. I discovered that you also need to return YES for the NSURLAuthenticationMethodHTTPBasic in the
canAuthenticateAgainstProtectionSpace:
method, otherwise it wont work.实现 NSURLConnection 委托方法:
这将使用连接成功字符串记录到控制台。查看响应数据,您可能会在其中找到有关连接的一些信息。
Implement NSURLConnection delegate method :
This will log to the console with connection successful string. See the response data, you may find some information about the connection in it.
这是项目的代码
Here is the code for project