gpt4 book ai didi

swift - AlamoFire.Request 中的多个参数

转载 作者:行者123 更新时间:2023-11-28 07:30:58 25 4
gpt4 key购买 nike

我正在尝试访问 Spotify 的网络 API。我目前正在使用 Alamofire 来请求只需要一个 token 的搜索操作。但是,我不明白为什么它不允许我发送多个参数。

let headers = ["Authorization": "Bearer {your access token}"]
var searchURL = "https://api.spotify.com/v1/search?q=Odesza&type=track"

AF.request(.GET, url, headers: headers)
.responseJSON { response in
debugPrint(response)
}

最佳答案

Alamofire 在将参数格式化为请求 url 方面做得很好。正如您使用 .post 方法将参数传递给 AF 请求函数一样,您也将参数 [string : any] 传递给 .get 方法的 AF 请求。不同之处在于 .post 会将参数放在 request.body/data 中,而 .get 会将参数格式化为带有 ?q=my_search_string 的 url

大致是这样的:

设参数:[string :any] = ["q": "odesza", "type":"track"]AF.request(.GET, url, parameters:params, headers: headers) .responseJSON { response in debugPrint(response

关于swift - AlamoFire.Request 中的多个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54727731/

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