gpt4 book ai didi

ios - Swift 5 & Alamofire 5 : GET method ERROR: Alamofire. AFError.URLRequestValidationFailureReason.bodyDataInGETRequest(22 字节)

转载 作者:行者123 更新时间:2023-12-01 16:05:49 31 4
gpt4 key购买 nike

我正在尝试使用 Alamofire 从数据库中获取记录。我在 GET 请求中发送参数如下。

let headers : HTTPHeaders = ["x-access-token": "\(t)","username":"\(Base.sharedManager.user)","password":"\(Base.sharedManager.pass)"]
let parm : [String: Any] = ["search_str" : self!.searchStr]
// let searchUrl = Base.sharedManager.URL+"questions/get/"+self!.searchStr
let searchUrl = Base.sharedManager.URL+"questions/get/"

AF.request(searchUrl, method: .get, parameters: parm, encoding:JSONEncoding.default , headers: headers, interceptor: nil).response { (responseData) in
guard let data = responseData.data else {
debugPrint("Error getting question data", responseData.error as Any)
self?.showNoResults()
return
}

do {
let sResults = try JSONDecoder().decode(SearchResults.self, from: data)
self!.searchReturn = [sResults]
self!.qSearchTV.reloadData()
} catch {
self?.showNoResults()
print("Error retriving questions \(error)")
}
}

执行上述代码时出现以下错误:
“获取问题数据时出错”可选(Alamofire.AFError.urlRequestValidationFailed(原因:Alamofire.AFError.URLRequestValidationFailureReason.bodyDataInGETRequest(23 字节)))

最佳答案

使用URLEncoding.default而不是 JSONEncoding.default

AF.request(path, 
method: .get,
parameters: params,
encoding: URLEncoding.default,
headers: nil)
.response { (responseData) in

}

关于ios - Swift 5 & Alamofire 5 : GET method ERROR: Alamofire. AFError.URLRequestValidationFailureReason.bodyDataInGETRequest(22 字节),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60960976/

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