Search code examples
iosobjective-cauthenticationnsurlrequestautologin

iOS NSURLRequest Login Programmatically to a Website


I was wondering how I can programatically login to a website. I have login credentials. How can I access the website with my login credentials programatically. Note: this is for personal use and the credentials are going to be hard coded.


Solution

  • Depends on what you want to do. If you are trying to log the user into an actual web page, you can use something like the answer I posted on this question (link).

    However, it sounds like you want to log a user in to a website without them having to go through a web view. In this case, the process will almost certainly require some sort of back-end server. The approach in this case would be to send a secure POST request to the server with the login credentials. Then, the server will give you a response (most likely with a token that you'll be able to use for future requests to that server).

    A quick example of a POST request can be found here. However, I would highly recommend using a library such as AFNetworking (what I use), and you should read up more on this process.