我使用以下代碼:爲什麼在收到一個302響應時會得到兩個redirectResponses?
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSHTTPURLResponse *)response {
NSLog(@"Received redirect Response: %@ %@", [response allHeaderFields], [NSHTTPURLResponse localizedStringForStatusCode:[response statusCode]]);
return request;
}
當我接收302與下面的頭數據:
< 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
這是在gdb控制檯輸出:
2010-03 -03 08:42:03.265 MyProg [68106:207]收到重定向響應: (null)服務器錯誤2010-03-03 08:42:14.414 MyProg [68106:207] 收到重定向響應:{
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」;
位置=「<new Location>
」;
Server =「lighttpd/1.4.19」;
Vary =「Accept-Encoding」; }發現
當使用捲曲我只得到一個響應和tracedump告訴相同的,所以我相信,服務器只發送一個重定向。
爲什麼這個選擇器調用兩次?
我發現,檢驗該請求時,在所述第一呼叫收到原始請求和在所述第二呼叫的空HTTPBody具有以下的HTTPHeader: (GDB)PO [請求allHTTPHeaderFields] { 接受=「*/*「; 「Accept-Encoding」=「gzip,deflate」; 「Accept-Language」=「en-us」; } – maxbareis 2010-03-03 08:29:58