gpt4 book ai didi

ios - 收到错误不支持的授权类型?

转载 作者:可可西里 更新时间:2023-11-01 04:37:18 26 4
gpt4 key购买 nike

我无法登录使用 Oath-2 的应用程序并收到 unsupported_grant_type 错误。我正在使用 Alamofire 发布登录数据但无法成功。我在哪里做错了?我无法解决问题。

函数发送反馈()

func sendFeedback(){


let parameters = [

"UserName": username_textfield.text! as String,
"Password": password_textfield.text! as String,
"grant_type": "Password" as String,
]


Alamofire.upload(multipartFormData: { multipartFormData in

for (key, value) in parameters {
multipartFormData.append((value.data(using: .utf8))!, withName: key)
}}, to: "http://192.168.100.5:84/Token", method: .post, headers: ["Authorization": "auth_token"],
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.response { [weak self] response in
guard self != nil else {
return
}
debugPrint(response)
// self?.view.hideToastActivity()
self?.view.makeToast(message: "Send Successfull. !!!")

}
upload.uploadProgress(queue: DispatchQueue(label: "uploadQueue"), closure: { (progress) in


})
case .failure(let encodingError):
print("errorss:\(encodingError)")
}
})

}

我收到状态代码 400。如何解决这个问题?

最佳答案

试试这个,这可能对你有帮助

let headers = [
"Content-Type": "application/x-www-form-urlencoded"
]
let parameters = [

"UserName": username_textfield.text! as String,
"Password": password_textfield.text! as String,
"grant_type": "password",
]
// let url = NSURL(string: "http://192.168.100.5:84/Token")!
Alamofire.request("http://192.168.100.5:84/Token", method: .post, parameters: parameters, encoding: URLEncoding.httpBody, headers: headers).responseJSON { (response:DataResponse<Any>) in

switch(response.result) {

case .success(_):
if response.result.value != nil{
// print(response.result.value ?? )
let statusCode = (response.response?.statusCode)!
print("...HTTP code: \(statusCode)")
}
break

case .failure(_):
// print(response.result.error ?? )
break

}
}

关于ios - 收到错误不支持的授权类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44694552/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com