gpt4 book ai didi

swift - 我无法在任何 api 中的 swift 项目的后期请求中发送正文中的数据

转载 作者:搜寻专家 更新时间:2023-11-01 06:50:19 26 4
gpt4 key购买 nike

我无法在任何 api 中发送 swift 项目的后期请求中的数据。如果我发送日期以在 url 中添加,那么 api 将响应。

let url: String = "https://maps.googleapis.com/maps/api/place/autocomplete/json" 
let para = ["key":googlekey, "components":"country:ids", "input":str, "types": "address"]
Alamofire.request(url, method: .post,parameters: para, encoding: JSONEncoding.default, headers: nil)
.responseJSON { dataResponse in

最佳答案

因此,正如我正确理解的那样,您正在使用 Google Maps API,并且您尝试执行的请求是 GET 请求,这意味着您需要在 URL 本身而不是正文中指定请求参数。我认为你的请求应该是这样的

    let googleKey = "your api key"
let url: String = "maps.googleapis.com/maps/api/place/autocomplete/json?input=Apple&components=country:ids&input=\(str)&types=adress&key=\(googleKey)"
Alamofire.request(url, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON

希望这会有所帮助。

关于swift - 我无法在任何 api 中的 swift 项目的后期请求中发送正文中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57787886/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com