Is there any way to add HTTP header to NSURLRequest
object? I used to add them in NSMutableURLRequest
using:
[request addValue:@"PC" forHTTPHeaderField:@"machineName"]
Is there any way to add HTTP header to NSURLRequest
object? I used to add them in NSMutableURLRequest
using:
[request addValue:@"PC" forHTTPHeaderField:@"machineName"]
I don't think you can modify the HTTP Headers of a
NSURLRequest
. I think you're trying to modify aNSURLRequest
object that you didn't initialize?You could create a
mutableCopy
of your request and then set the header fields with the following method:After that you can
copy
the mutable request back onto yourNSURLRequest
variable.EDIT: Added example below
Already answered (and thanks to those answers), but here's a more simple example: