NSURLRequest / NSURLConnection ios 5.0 v/s earlier versions
I am trying to use NSMutableRequest and NSURLConnection to fetch a compressed file from the server . Here's the code I'm using:
NSMutableURLRequest *newRequest = [NSMutableURLRequest requestWithURL:downloadUrl
cachePolicy:NSURLRequestReloadIgnoringCacheData
开发者_如何学C timeoutInterval:30.0];
[newRequest setValue:@"Y29tLm5vbWFkZ......" forHTTPHeaderField:@"Authorization"];
NSURLConnection *connection = [NSURLConnection connectionWithRequest:newRequest delegate:self];
if (!connection) {
[self handleDownloadError];
}
And I am using the same NSURLConnectionDelegate method
didReceiveResponse, didReceiveData, connectionDidFinishLoading, didFailWithError
But, I am getting different responses when I run this code in ios 4.3 or earlier version (it downloads the zipped file) and ios 5.0 ( returns a JSON saying "Authentication Failure.").
ios 5.0 has introduced many new methods for NSURLConnectionDelegate. But I am not sure if this is an issue regarding changed api for ios 5.0 or it's the server code that is handling the same request in different ways. Does anyone know what may be the problem ?
iOS5 changed the way HTTP headers are capitalized, also removed spaces at least from end. Verify what is the actual HTTP headers you receive by printing them into console:
- (void)connection:(NSURLConnection *)aConnection
didReceiveResponse:(NSURLResponse *)aResponse
{
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)aResponse;
NSLog(@"Response headers :%@", [httpResponse allHeaderFields]);
}
Btw did you notice that those methods you're listing are marked as "Available in iOS 2.0 through iOS 4.3" at the Apple iOS Developer Library docs for NSURLConnection?
精彩评论