Categories
Mastering Development

Swift 5 & Alamofire 5 : GET method ERROR: Alamofire.AFError.URLRequestValidationFailureReason.bodyDataInGETRequest(22 bytes)

I am trying to get records from Database using Alamofire. I am sending parameters in GET request as below.

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)")
                       }

                   }

Got the error below when above code executed:
“Error getting question data” Optional(Alamofire.AFError.urlRequestValidationFailed(reason: Alamofire.AFError.URLRequestValidationFailureReason.bodyDataInGETRequest(23 bytes)))

Leave a Reply

Your email address will not be published. Required fields are marked *