Android Https Post and Get

Yesterday, i have done an piratical test for an interview. The task provided is to post a username and password to an https url and also to  get the response results using an https connection in another url. I have successfully completed the task, but it took me around five hours. I wasted lot of time in researching on how to do an https post. Therefore i thought i could share some of the important information, so that it will we helpful for some one. please not i am not going to share the entire solution.

First create an custom socket factory inside your package. Use the below code.

Add this function inside your MainActivity class to create a httpClient using custom socket factory. As shown in the below code.

Then Run an Async task for https post like this.

And if you want to do an https Get request. See the code below

Hope this helps. Feel free to ask any question if you have in the comments section below.Tnx, Happy coding 🙂