[ad_1]
I am getting an error whereas making an attempt to encode a parameter right into a request url.
Right here is my perform to get the request url:
func asURLRequest() throws -> URLRequest {
let url = attempt baseURL.asURL().appendingPathComponent(path)
var request = URLRequest(url: url)
request.methodology = methodology
if methodology == .get {
request = attempt URLEncodedFormParameterEncoder().encode(parameters, into: request)
} else if methodology == .submit {
request = attempt JSONParameterEncoder().encode(parameters, into: request)
request.setValue("software/json", forHTTPHeaderField: "Settle for")
}
return request
}
It’s working when the parameter is a dictionary like [“id”: 1]. The url can be:
http://…/api/v1/objects/?id=1
I need to go the parameter 1 solely, so the url can be like this:
http://…/api/v1/objects/1
Nevertheless it does not work, I get this error from Alamofire:
requestRetryFailed(retryError:
Alamofire.AFError.requestRetryFailed(retryError:
Alamofire.AFError.parameterEncoderFailed(purpose:
Alamofire.AFError.ParameterEncoderFailureReason.encoderFailed(error:
Alamofire.URLEncodedFormEncoder.Error.invalidRootObject(“string(“1″)”)))
[ad_2]
