There are a couple of issues.
Your method
getToken:andPassword:
should be asynchronous.Improper use of
NSOperationQueue
(you don't need that)No Content-Type header specified
Omitting parameter encoding in the Query component of the URI (
x-www-form-urlencoded
)Some lack of experience which
NSURLConnection
:Don't use class convenience methods unless you know exactly that your request works with the implemented default behavior (for requests with authentication this is almost always never the case). Please read the official docs
So, for a solution, I would suggest the delegate approach of either NSURLConnection
or NSURLSession
. See examples and code snippets in the official docs already mentioned above.
You will have to handle an authentication challenge, where you provide the credentials. This also frees you from the error prone and inconvenient need to percent encode the parameters if you would put them into the URL or the body.
You should also use https
.