I am trying to perform POST request with custom header but I keep getting this exception and app failure:
'NSUnknownKeyException', reason: '[<AFHTTPRequestSerializer 0xa21af80> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key X-Auth-AID.'
I have followed instructions on forum of the code on GitHub:
Both this
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
AFHTTPRequestSerializer *requestSerializer = [AFHTTPRequestSerializer serializer];
[requestSerializer setValue:@"test" forKey:@"X-Auth-AID"];
manager.requestSerializer = requestSerializer;
and this:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager.requestSerializer setValue:@"test" forKey:@"X-Auth-AID"];
is throwing the exception...
The method you want to use is setValue:forHTTPHeaderField:, which is defined on AFHTTPRequestSerializer. The method you're currently calling is setValue:forKey:, which is defined in the the NSKeyValueCoding protocol and not what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With