Unable to add a header to NSMutableRequest

44 Views Asked by At
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:tempURL]] autorelease];
[request setValue:encryptedValue forHTTPHeaderField:@"EncString"];

I could spot all other headers in the request but this specific header is missing, can any one let me know what could be the reasons.

1

There are 1 best solutions below

2
Matic Oblak On

I have tried the following code:

NSString *tempURL = @"https://stackoverflow.com/questions/50701101/unable-to-add-a-header-to-nsmutablerequest";
NSString *encryptedValue = @"whatever_that_has_no_special_characters_or_values_that_would_make_you_think_it_is_relevant_to_reproduce_this_issue";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:tempURL]];    
[request setValue:encryptedValue forHTTPHeaderField:@"EncString"];
NSLog(@"%@", request.allHTTPHeaderFields);

The output is:

{
    EncString = "whatever_that_has_no_special_characters_or_values_that_would_make_you_think_it_is_relevant_to_reproduce_this_issue";
}

which looks good. There is no reason to suspect the code you provided is responsible for the issue. Maybe you should check one of the following:

  • Is encryptedValue truly a valid object to be placed into header (is string, not too long, no very special characters)
  • Is the object you are printing really this specific request (printing NSLog(@"%p", request); returns same result)
  • In no place in this object a herder is being removed (if nothing else subclass NSMutableURLRequest and override relevant methods to track what is going on)

If none of these work create a post with additional details on what you have done, where are you checking these headers and "could spot all other headers".