If I know that authentication is required for my server API, is it faster/better to directly force authentication using http header instead of waiting for the server to return 401 response and then respond to it inside NSURLConnection delegate method connection:didReceiveAuthenticationChallenge:?
Share
The “easier way” to provide authentication credentials to a server is to use NSURLConnection delegate method
where you can provide credentials similar to this
What will happen is that you first call server with your GET/POST request and if the server requires authentication, and credentials were not provided inside HTTTP header, it will (hopefully) respond with 401 response. The above method will trigger and provide supplied credentials.
But if you know that your server will always require authentication, it is not efficient to make this extra round of client/server communication and you will be better off to provide your credentials straight away inside the HTTP header.
The method of providing credentials inside HTTP header is simple apart from the fact that iOS doesn’t come with a method to encode to BASE64.