IOS Swift Alamofire POST request error Code=-1002

Swift request code:

import Alamofire
let parameters:[String : Any] = [
    "action": "login",
    "login": "admin",
    "password": "admin"
]

let urlString = "localhost:8888/index.php"

Alamofire.request(urlString, method: .post, parameters: parameters).responseJSON { response in
    switch response.result.isSuccess {
    case true:
        print("!")
    case false:
        print(response.result.error!)
    }
}

error code:

Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSUnderlyingError=0x6080000576d0 {Error Domain=kCFErrorDomainCFNetwork Code=-1002 "(null)"}, NSErrorFailingURLStringKey=localhost:8888/index.php, NSErrorFailingURLKey=localhost:8888/index.php, NSLocalizedDescription=unsupported URL}

Mar.12,2021

the requested URL needs to be added with http/ https://
URL. By default, AF will not automatically complete a default value for URL without protocol

Menu