Raphael Raphael - 1 year ago 113
iOS Question

NSURLRequest setting the HTTP header

I need to set the HTTP header for a request. In the documentation for the NSURLRequest class I didn't find anything regarding the HTTP header. How can I set the HTTP header to contain custom data?

Answer Source

You need to use a NSMutableURLRequest

NSMutableURLRequest* request = [[[NSMutableURLRequest alloc] initWithURL:url]

[request setValue:VALUE forHTTPHeaderField:@"Field You Want To Set"];

or to add a header:

[request addValue:VALUE forHTTPHeaderField:@"Field You Want To Set"];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download