SolvedMoya Not able to get URLEncoding working correctly when there is "?" and the method is "POST"
✔️Accepted Answer
try use this
var baseURL: URL{
switch self {
case .chagePassword(_,_,let token):
return URL(string: "base_url?token=\(token)")!
default:
return URL(string: "base_url")!
}
}
var path:String{
switch self {
case .chagePassword:
return "/api/update-password"
}
}
and url request will like this "base_url/api/update-password?token="114149814189"
Other Answers:
@avicks
@pedrovereza
the problem is instead of getting this as
URL: "http://myWebSErvice/products?id_category=30"
I get this: %3F
URL: "http://myWebSErvice/products%3Fid_category=30"
and when the "?" becomes "%3F" , the webservice throws error this "A potentially dangerous Request.Path value was detected from the client (?).
"
What i want is only to send the request with ? not with %3F
@iballan Looks like I have found solution. You should use own Endpoint and url stay correct without changing from '?' to '%3F'
This my real method that works for this situation
let authPlugin = AccessTokenPlugin(token: token)
let provider = RxMoyaProvider<Service>(endpointClosure: {target in
return Endpoint(
url: "\(target.baseURL)\(target.path)",
sampleResponseClosure: { .networkResponse(200, target.sampleData) },
method: target.method,
parameters: target.parameters,
parameterEncoding: target.parameterEncoding
)
}, plugins: [authPlugin])
For me it didn't get yet.
The difference is that I'm using .get
But the problem still happens, it converts the "?" to "%3F"
I am using the last version of Moya and Alamofire with Swift 3
I am having trouble when the method is "POST" and there is url encoding
The url must be:
products?id_category=28
but it is converted to be:
products%3Fid_category=28
which is not working and giving 400 error on the server
where can I find this conversion and stop it for the requests ?
Here is the code i used: