Tutorial :NSURLConnection delegate doesn't get its didReceiveAuthenticationChallenge method on server status 401



Question:

I've setup a simple NSURLConnection to query an http-server.

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  

The server responds with code 401 and the WWW-Authenticate header set

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:  

I would imagine this would send a message to my delegate's connection: didReceiveAuthenticationChallenge: method, but it does not.

I've also implemented

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

Just to make sure it doesn't try to send along cached credentials from my keychain, which it does not.


Solution:1

The WWW-Authenticate header looks malformed, try:

WWW-Authenticate: Basic realm="My Realm"  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »