Swift 4- http request Post to login in website

186 Views Asked by At

I'm searching about how to send some data to a website. For example, I want to send username and password to a website and I want to check if the login is successful or not. I searched a lot but I don't know how to do it.

If anyone has a background in HTTP request POST in Swift, I hope you can help me to send this data to a website using Swift 4.

import UIKit
import Alamofire

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let urlString = "https://www.instagram.com/accounts/login"

        Alamofire.request(urlString, method: .get).authenticate(user: "username", password: "pwd").responseJSON
    }
}
1

There are 1 best solutions below

0
Vishal Parmar On

You have use with post method i am giving you example code like below

func loginAPI(){
    let params = ["username": "your username","password": "your password"]
     Alamofire.request("ApiURL", method: .post, parameters: params).responseJSON
     {
             response in
             print(response)

     }
}

Please check my code i hope it will help you