AFNetworking 2: Authorization header not included in request

Robert Audi

I have an app that uses AFNetworking 2. I am trying to make a request with an Authorization header. Here is the code I have at the moment:

NSURL                         *baseURL = [NSURL URLWithString:WLAPIBaseURL];
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:baseURL];
[manager.requestSerializer setAuthorizationHeaderFieldWithUsername:email password:password];
[manager GET:WLAPIEndpointMe parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
 } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
 }];

When I make the request, I get a 401 response. I monitored the request with Charles, and it turns out that the Authorization header is not included in the request...

I am sure this is not a problem with the server because when I make the same request with curl from the command-line, it works fine.

So, what am I doing wrong?

Robert Audi

I managed to make it work, by using credentials instead of setting the Authorization headers explicitly:

NSURL                         *baseURL = [NSURL URLWithString:WLAPIBaseURL];
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:baseURL];

NSURLCredential *credential = [NSURLCredential credentialWithUser:email
                                                         password:password
                                                      persistence:NSURLCredentialPersistenceNone];

manager.credential = credential;
[manager GET:WLAPIEndpointMe parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
 } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
 }];

I still do not understand why the headers were stripped out though...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

AFNetworking and Authorization Header

From Dev

How to set Authorization header in AFNetworking

From Dev

AFNetworking 2.0 and Request header

From Dev

AFNetworking send header with request

From Dev

Swift 2 How do you add authorization header to POST request

From Dev

Swift 2 How do you add authorization header to POST request

From Dev

Authorization header in Http Request in linkedin

From Dev

Request header field Authorization is not allowed

From Dev

Module passport-oauth2 in nodej.js: extra parameters to be included in the authorization request

From Dev

AFNetworking 2.0 Request w. Custom Header

From Dev

How can I add a request header with AFNetworking?

From Dev

How can I add a request header with AFNetworking?

From Dev

How to batch request with AFNetworking 2?

From Dev

Authorization header missing in PHP POST request

From Dev

How to send Authorization header with a request in Swagger UI?

From Dev

Guzzle HTTP - add Authorization header directly into request

From Dev

Authorization header not being sent in AJAX request

From Dev

angular $http GET request with authorization token header

From Dev

Sending Authorization Header with JWT in HTTP-Request

From Dev

Python requests: POST request dropping Authorization header

From Dev

Python POST request dropping Authorization header

From Dev

Python requests: POST request dropping Authorization header

From Dev

Why Authorization header is not send in API request in Angular?

From Dev

How to remove authorization header from request

From Dev

API Request with HTTP Authorization Header inside of componentDidMount

From Dev

Swagger Editor Not Passing Authorization in the Request Header

From Dev

jQuery - unable to execute ajax request with authorization header

From Dev

'Authorization' header sent with request, but missing from apache_request_headers()

From Dev

AFNetworking: download request by range of bytes (ie: only file header)

Related Related

  1. 1

    AFNetworking and Authorization Header

  2. 2

    How to set Authorization header in AFNetworking

  3. 3

    AFNetworking 2.0 and Request header

  4. 4

    AFNetworking send header with request

  5. 5

    Swift 2 How do you add authorization header to POST request

  6. 6

    Swift 2 How do you add authorization header to POST request

  7. 7

    Authorization header in Http Request in linkedin

  8. 8

    Request header field Authorization is not allowed

  9. 9

    Module passport-oauth2 in nodej.js: extra parameters to be included in the authorization request

  10. 10

    AFNetworking 2.0 Request w. Custom Header

  11. 11

    How can I add a request header with AFNetworking?

  12. 12

    How can I add a request header with AFNetworking?

  13. 13

    How to batch request with AFNetworking 2?

  14. 14

    Authorization header missing in PHP POST request

  15. 15

    How to send Authorization header with a request in Swagger UI?

  16. 16

    Guzzle HTTP - add Authorization header directly into request

  17. 17

    Authorization header not being sent in AJAX request

  18. 18

    angular $http GET request with authorization token header

  19. 19

    Sending Authorization Header with JWT in HTTP-Request

  20. 20

    Python requests: POST request dropping Authorization header

  21. 21

    Python POST request dropping Authorization header

  22. 22

    Python requests: POST request dropping Authorization header

  23. 23

    Why Authorization header is not send in API request in Angular?

  24. 24

    How to remove authorization header from request

  25. 25

    API Request with HTTP Authorization Header inside of componentDidMount

  26. 26

    Swagger Editor Not Passing Authorization in the Request Header

  27. 27

    jQuery - unable to execute ajax request with authorization header

  28. 28

    'Authorization' header sent with request, but missing from apache_request_headers()

  29. 29

    AFNetworking: download request by range of bytes (ie: only file header)

HotTag

Archive