2009-04-07 196 views
1

我已经设置了一个简单的NSURLConnection来查询一个http服务器。NSURLConnection委托没有得到它的didReceiveAuthenticationChallenge方法在服务器状态401

GET /path HTTP/1.1 
Host: 192.168.1.161:8282 
User-Agent: NetTest1.0 CFNetwork/441.0.2 Darwin/9.6.0 
Accept: */* 
Accept-Language: en-us 
Accept-Encoding: gzip, deflate 
Pragma: no-cache 
Connection: keep-alive 

服务器用代码401响应和WWW身份验证标头设置

HTTP/1.1 401 
Connection: close 
Pragma: no-cache 
Expires: Thu, 01 Dec 1994 16:00:00 GMT 
Cache-control: no-cache 
Cache-last-checked: Thu, 01 Dec 1994 16:00:00 GMT 
Last-modified: Tue, 07 Apr 02009 22:55:48 CEST 
Content-type: text/html; charset=iso-8859-1 
WWW-Authenticate: Basic realm: 

我想这将消息发送到我委托的连接:didReceiveAuthenticationChallenge:方法,但事实并非如此。

我也实现

- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection { 
    return FALSE; 
} 

只是为了确保它不会试图沿缓存凭据从我的钥匙串,它不发送。

回答

5

WWW身份验证头看起来格式不正确,请尝试:

WWW-Authenticate: Basic realm="My Realm" 
相关问题