NSURLConnection委托在服务器状态401上没有获得其didReceiveAuthenticationChallenge方法

时间:2009-04-07 21:07:54

标签: cocoa macos nsurlconnection core-foundation

我已经设置了一个简单的NSURLConnection来查询http服务器。

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-Authenticate标头集

进行响应
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;
}

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

1 个答案:

答案 0 :(得分:5)

WWW-Authenticate标头看起来格式不正确,请尝试:

WWW-Authenticate: Basic realm="My Realm"