views:

219

answers:

2

I'm getting pretty frustrated figuring out how to add a lowercase header field to an NSMutableURLRequest.

NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:MyURLString]];
[urlRequest setValue:@"aValue" forHTTPHeaderField:@"field"];

In the example above, "field" gets switched to "Field," since the header field names are case insensitive. I would think this shouldn't happen, but it does. The API I am working with is case sensitive, so my GET request is ignored. Is there any way to override the case switch?

+2  A: 

HTTP header fields are supposed to be case insensitive, so you need to fix your API.

Graham Lee
Or get the 3rd party to fix theirs!
Frank Shearar
@Frank or that.
Graham Lee
Well, I'll email their support and see how far I get! I was hoping there would be a way for me to change the case of my request, but I can't find anything to dodge the case switch. Thanks!
Drewsmits
+1  A: 

I have written a blog post on the topic: Fixing -[NSMutableURLRequest setValue:forHTTPHeaderField:] I suggest you to read it. You will learn how to fix this problem and why you should not fix it.

0xced