Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass an Authorization token for AFNetworking 2.0 as it is deprecated

I'm Currently working on a project where I'm using AFNetworking 2.0 library to GET and POST the data to and from server.In some cases i wanted to pass a token value as header type for the request with AFHTTPRequestOperationManager. So far this is what i found

[manager.requestSerializer setAuthorizationHeaderFieldWithToken:TOKEN_VALUE];

but it is deprecated in version 2.0, and i also learned in version AFNetWorking 2.2.1 it is not deprecated. But i couldn't find the library with version 2.2.1 to download it. Please help me out if there is any other way that i can set token as my header for AFHTTPRequestOperationManager. And also any link to download the AFNetworking latest version library.

like image 443
Madhu Avatar asked Nov 27 '25 12:11

Madhu


1 Answers

This is the deprecation message in the AFNetworking docs:

This method has been deprecated. Use setValue:forHTTPHeaderField: instead. (Deprecated: This method has been deprecated. Use -setValue:forHTTPHeaderField: instead.)

The docs for this method setValue:forHTTPHeaderField: can be found here. To set a token as your header with the AFNetworking method setValue:forHTTPHeaderField: try:

AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager manager] initWithBaseURL:@"http://someurl.com"];

[manager.requestSerializer setValue:@"Token token=token_name" forHTTPHeaderField:@"Authorization"];
like image 103
Jonathan Yeong Avatar answered Nov 30 '25 06:11

Jonathan Yeong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!