我正在构建一个检查域可用性的应用程序。现在,我正在使用 goDaddy API;根据 goDaddy 的说法,检查 URL 可用性的方法是通过以下 cURL 命令:
curl -X GET -H "Authorization: sso-key {API_KEY}:{API_SECRET}" "https://api.godaddy.com/v1/domains/available?domain=example.guru"
现在,我正在尝试将该 cURL 命令翻译成 Swift。我正在使用 Alamofire;但是,当我提出请求时,会出现如下错误:
必须指定凭据
我想知道如何解决这个问题。这是我当前的代码:
class ViewController: UIViewController {
let key = "KEYKEYKEY"
let secret = "SECRETSECRET"
var headers: HTTPHeaders = [:]
override func viewDidLoad() {
super.viewDidLoad()
let credential = URLCredential(user: key, password: secret, persistence: .forSession)
Alamofire.request("https://api.godaddy.com/v1/domains/available?domain=example.guru")
.authenticate(usingCredential: credential)
.responseJSON { response in
debugPrint(response)
}
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}