小编Sak*_*Cho的帖子

NSURLConnectionDelegate willSendRequestForAuthenticationChallenge将不会在iOS 8上调用

我的服务器提供了几种身份验证方法:NTLM和摘要.
我的iOS客户端不会处理NTLM身份验证,因此我实现connection:willSendRequestForAuthenticationChallenge:委托拒绝NTLM,然后仅使用正确的凭据进行摘要身份验证质询.
到目前为止,iOS 7上的一切正常.

但在iOS 8,我发现了一个奇怪的现象:
connection:willSendRequestForAuthenticationChallenge:代表不会在大部分时间(95%)被调用!

我得到了这个错误:

Error: Error Domain=NSPOSIXErrorDomain Code=54 "The operation couldn’t be completed. Connection reset by peer" 
UserInfo=0x16520fb0 {_kCFStreamErrorCodeKey=54, 
NSErrorPeerAddressKey=<CFData 0x16682e40 [0x2f752440]>{length = 16, capacity = 16, bytes = 0x10020d7eac12780b0000000000000000}, 
NSErrorFailingURLKey=http://SERVER_IP:SERVER_PORT/Tunnel/Message.aspx, 
NSErrorFailingURLStringKey=http://SERVER_IP:SERVER_PORT/Tunnel/Message.aspx, 
_kCFStreamErrorDomainKey=1}
Run Code Online (Sandbox Code Playgroud)

只有5%的时间正确调用代理并照常工作.

下面显示了如何将我的请求发送到服务器并处理身份验证质询:

- (void)postRequest
{
    NSString *IP = SERVER_IP;
    int port = SERVER_PORT;

    NSString *url = [NSString stringWithFormat:@"http://%@:%d/Tunnel/Message.aspx", IP, port];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];

    NSString *xml = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?><GetServerInfo></GetServerInfo>"];
    [request …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nsurlconnection ios ios8

11
推荐指数
1
解决办法
6527
查看次数

标签 统计

ios ×1

ios8 ×1

iphone ×1

nsurlconnection ×1

objective-c ×1