开发者

How to add lowercase field to NSURLRequest header field?

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 开发者_StackOverflowexample 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?


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


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.


can u please try with addValue(_:forHTTPHeaderField:)?

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜