Apple's iPhone: Accessing HTTP Headers from an NSURLRequest
By teendad
Programming the iPhone from Apple
Using NSURLRequest to send the HTTP Headers that Accompanied a Query Response
One of the more quirky programming (coding) tasks with the Apple iPhone relates to headers for http connections, and although not difficult, can be quite frustrating if the syntax isn't correct.
In the NSHTTPURLResponse class, the headers for an HTTP connection are included. By sending the allHeaderFields message with the NSHTTPURLResponse variable, you can easily get the headers out as NSDictionary.
Although synchronous requests are problematic due to blocking issues, populating an NSHTTPURLResponse in this manner is fairly straightforward:
In the case of an asynchronous request, the code structure is more complicated. When using the callback connection:didReceiveResponse:, the second parameter passed is NSURLResponse. You can send it to an NSHTTPURLResponse like so:
iPhone Accessories
![]() | Amazon Price: $2.95 List Price: $44.95 |
![]() | Amazon Price: $0.01 List Price: $24.99 |
![]() | Amazon Price: $0.01 List Price: $0.00 |
Comments
No comments yet.


