How to add string field to NSURLRequest header field?

I am very upset to figure out how to add a lowercase header field to NSMutableURLRequest.

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

In the above example, the "field" switches to "Field" because the header field names are not case sensitive. I would think that this should not be, but it is. The API I'm working with is case sensitive, so my GET request is ignored. Is there a way to override the case switch?

+3
source share
3 answers

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

+2

Is it possible to try with addValue (_: forHTTPHeaderField :)?

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

Source: https://habr.com/ru/post/1739103/


All Articles