7

I'm developing an iOS app that makes frequent requests to a web server, and I'm using AFNetworking (which I very much like). However, I'm running into a problem with authorization that I just can't solve.

The server requires me to provide an authorization header in order to get the response that I want. Specifically, the authorization headers should be like so:

Authorization = "ApiKey some-user-name:someNumericalApiKey"

I'm using AFNetworking throughout the project, and everything works fine, except for this authorization issue. I'm using the following code:

[myClient setDefaultHeader:@"Authorization" value:@"ApiKey some-user-name:someNumericalApiKey"];

where myClient points to an AFHTTPClient object. Strange enough, when I log the request in XCode using AFHTTPRequestOperationLogger, the logger claims that I have the correct headers set. However, the authorization header does not seem to reach the server - I can't see it in the server log.

To isolate the problem, I've tried to make the exact same request using good old NSURLRequest, as well as curl, and the requests library in Python - all of these work fine, i.e. the authorization header is sent & received (i.e. I can see it in the server log), and the server response is what it should be.

If anyone has run into the same problem (and has found a solution) I would very much appreciate to hear from you.

Thanks.

4

2 に答える 2

0

操作を手動で構築した場合、defaultHeaders は適用されません。これが問題の原因である可能性があります。

于 2012-10-09T04:33:18.280 に答える