AlamoFire.Request中的多个参数

问题描述 投票:1回答:1

我正在尝试访问Spotify的Web API。我目前正在使用Alamofire请求只需要令牌的搜索操作。但是,我无法弄清楚为什么它不会让我发送多个参数。

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)
    }
swift alamofire
1个回答
0
投票

Alamofire可以很好地将参数格式化为请求URL。就像使用.post方法将参数传递给AF请求函数一样,您也可以将参数[string:any]传递给.get方法的AF请求。区别在于.post会将参数放在request.body / data vs. .get中,将参数格式化为url,其中包含?q = my_search_string

类似的东西:

让params:[string:any] = [“q”:“odesza”,“type”:“track”] AF.request(.GET,url,参数:params,headers:headers).responseJSON {debug in DebugPrint(响应

© www.soinside.com 2019 - 2024. All rights reserved.