开发者

Why do I get two redirectResponses when receiving one 302 response?

I use the following code:

- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:开发者_Python百科(NSURLRequest *)request redirectResponse:(NSHTTPURLResponse *)response {
NSLog(@"Received redirect Response: %@ %@", [response allHeaderFields], [NSHTTPURLResponse localizedStringForStatusCode:[response statusCode]]);
return request;
}

When I receive a 302 with the following header data:

< HTTP/1.1 302 Found  
< Date: Wed, 03 Mar 2010 07:47:17 GMT  
< Server: lighttpd/1.4.19  
< Content-length: 0  
< Content-type: text/html;charset=utf-8  
< Location: `<new Location>`  
< Vary: Accept-Encoding  

this is the output in gdb console:

2010-03-03 08:42:03.265 MyProg[68106:207] Received redirect Response: (null) server error 2010-03-03 08:42:14.414 MyProg[68106:207] Received redirect Response: {

Connection = "Keep-Alive";

"Content-Encoding" = gzip;

"Content-Length" = 20;

"Content-Type" = "text/html;charset=utf-8";

Date = "Wed, 03 Mar 2010 07:42:10 GMT";

"Keep-Alive" = "timeout=15, max=100";

Location = "<new Location>";

Server = "lighttpd/1.4.19";

Vary = "Accept-Encoding"; } found

When using Curl I only get one response and tracedump tells the same, so I am sure that the server sends only one redirect.

Why is this selector called twice?


connection:willSendRequest:redirectResponse: gets called before every request, so it is called once on the original request, which was not a redirect so response is nil; then it gets called when loading the redirection target, where response is the 302 response to the initial request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜