鍍金池/ 問答/iOS/ iOS Swift Alamofire POST請(qǐng)求報(bào)錯(cuò)Code=-1002

iOS Swift Alamofire POST請(qǐng)求報(bào)錯(cuò)Code=-1002

Swift請(qǐng)求代碼:

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("數(shù)據(jù)獲取成功!")
    case false:
        print(response.result.error!)
    }
}

錯(cuò)誤代碼:

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}

圖片描述

回答
編輯回答
執(zhí)念

請(qǐng)求的URL需要加上http/https://
URL、AF默認(rèn)不會(huì)去將沒有協(xié)議的URL自動(dòng)補(bǔ)全一個(gè)默認(rèn)值

2017年7月8日 23:19