我正在尝试使用 Alamofire 向此 url 发出请求:
https://overpass-api.de/api/interpreter?data=[out:json];(way[highway~"^(motorway)$"][!maxspeed](around:5,45.792790,3.062686););out%20tags;
但它包含双引号,并且转换为 URL 失败。
我已经"用反斜杠逃脱了
let urlString = "https://overpass-api.de/api/interpreter?data=[out:json];(way[highway~\"^(motorway)$\"][!maxspeed](around:5,45.792790,3.062686););out%20tags;"
但是当我在 URL 中转换字符串时,它返回 nil
let url = URL(string: urlString)
我试过用 替换"符号%22,但它仍然无法正常工作。我尝试使用 addPercent 但它导致错误的 url 并返回错误 400 或 404
let urlWithEconding = urlString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
我还尝试使用 AlamoFire 方法进行 url 转换和编码,但我无法使其工作......