Moya: How to set in the APIProvider or somewhere to make sure the url response using right url ?

Created on 16 Feb 2017  路  5Comments  路  Source: Moya/Moya

Hi guys i have this response from my call (using latest moya) . this only happened in GET i already encoded my string to make sure the url escaped but why the url response in the log keep using percent ? anyone can give any solutions ?

i want to made this %3F into ? , i already set in the APIProvider to removingpercentencoding but keep happening..

"Moya_Logger: [16/02/2017 13:01:16] Response: <NSHTTPURLResponse: 0x60000022ad80> { 
URL: https://someurl.com/v1/presets%3Funflatten=1

Thanks

question

Most helpful comment

Found it right after asking.. 馃槄

So for those of you who're looking for the answer, I solve it by using NSURLComponents like that :

let urlComponents = NSURLComponents(string: "http://you/base/url/route")!
urlComponents.path = "/your/path"
urlComponents.query = "your/query"

Do not add the question mark ('?') inside your query, it'll be added automatically !
And then you just build your url this way :

let url = urlComponents.url!

Enjoy ! 馃憤馃徎

All 5 comments

Done, solved by myself by edit the url endpoint...

Would you mind telling us how you did solve it ? 馃槒
I'm having the exact same issue when sending the request but haven't found a way to fix it yet.. 馃様

Thanks in advance! 馃槈

Found it right after asking.. 馃槄

So for those of you who're looking for the answer, I solve it by using NSURLComponents like that :

let urlComponents = NSURLComponents(string: "http://you/base/url/route")!
urlComponents.path = "/your/path"
urlComponents.query = "your/query"

Do not add the question mark ('?') inside your query, it'll be added automatically !
And then you just build your url this way :

let url = urlComponents.url!

Enjoy ! 馃憤馃徎

@Ank49 cool man.. sorry just read it.. My approach little bit different. I edit the urlendpoint something like this


//setting the header
        let endpointClosure = { (target: API) -> Endpoint<API> in
            let url = target.baseURL.appendingPathComponent(target.path).absoluteString.removingPercentEncoding!
            let defaultEndpoint = Endpoint<API>(URL: url, sampleResponseClosure: {.networkResponse(200, target.sampleData)}, method: target.method, parameters: target.parameters)
            return defaultEndpoint.adding(httpHeaderFields: ["Accept": "application/json", "Content-Type" : "application/json", "Authorization" : token!, "X-Fingi-Signature":authSign], parameterEncoding: JSONEncoding.default)
        }

Thanks for sharing! Your approach is much more neat and simple !
Never saw this mentioned anywhere, kind of awkward, not known enough maybe..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PlutusCat picture PlutusCat  路  3Comments

pedrovereza picture pedrovereza  路  3Comments

fenixsolorzano picture fenixsolorzano  路  3Comments

kamwysoc picture kamwysoc  路  3Comments

mwawrusch picture mwawrusch  路  3Comments