0

I am using Alamofire to perform call to google snap to road but it is returning me nil as response. But if i perform the call from postman it returns me the response as expected.

 let url: String = "https://roads.googleapis.com/v1/snapToRoads?interpolate=true&key=my_api_key&path=47.5247062,8.8880707|47.5247062,8.8880707|47.5288075,8.8752297"
        Alamofire.request(url, method: .get).responseJSON {
            response in
            print(response.request)
            print(response.response)
            print(response.response?.statusCode)
            self.wayPointInteractorOutput.onSnapToRoadResponse()
        }

It returns me nil as response and Alamofire.AFError.invalidURL as error. But if i use the same url from postman it is returning me the response properly.

Anik Dey
  • 616
  • 8
  • 17
  • I'm not sure that this is duplicate. He has problem that he didn't provide valid API key as parameter and he also doesn't work with `response.value` – Robert Dresler Dec 23 '18 at 13:01
  • @RobertDresler This URL does not work unescaped at all. Please note the error message *invalidURL* – vadian Dec 23 '18 at 13:02
  • @vadian ok, you're right. If he has problem with other things, he should ask new question. – Robert Dresler Dec 23 '18 at 13:04
  • @vadian you are right. The URL was not unescaped at all. this line solved my problem let escapedString = originalString.addingPercentEncoding(withAllowedCharacters:NSCharacterSet.urlQueryAllowed) as! String – Anik Dey Dec 23 '18 at 13:29
  • Don't cast. The result **is** `String`. Isn't there a warning? Just force unwrap `... .urlQueryAllowed)!` – vadian Dec 23 '18 at 13:32
  • @vadian force unwraped. Thanks a lot brother. – Anik Dey Dec 23 '18 at 13:36
  • Send apiKey and path data as a data in alamofire rest call and check URL – Abhishek Jadhav Dec 23 '18 at 14:34

0 Answers0