create your own

Apple's iPhone: Accessing HTTP Headers from an NSURLRequest

64
rate or flag this page

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:

Click on the image of code to increase the size and more clearly read the text.
Click on the image of code to increase the size and more clearly read the text.

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:

Click on the image of code to increase the size and more clearly read the text.
Click on the image of code to increase the size and more clearly read the text.

Apple's iPhone in the News

Print   —   Rate it:  up  down  flag this hub

Comments

RSS for comments on this Hub

No comments yet.

Submit a Comment

Members and Guests

Sign in or sign up and post using a hubpages account.


optional


  • No HTML is allowed in comments, but URLs will be hyperlinked
  • Comments are not for promoting your hubs or other sites

working