Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift AlamoFire.Request中有多个参数_Swift_Alamofire - Fatal编程技术网

Swift AlamoFire.Request中有多个参数

Swift AlamoFire.Request中有多个参数,swift,alamofire,Swift,Alamofire,我正在尝试访问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: h

我正在尝试访问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)
    }

Alamofire在将参数格式化为请求url方面做得很好。正如使用.post方法将参数传递给AF请求函数一样,您也将参数[string:any]传递给.get方法的AF请求。区别在于.post将把参数放在request中。body/data vs..get将用?q=my_search_字符串将参数格式化到url中

大致如下:

Let参数:[string:any]=[“q”:“odesza”,“type”:“track”]
AF.request(.GET,url,parameters:params,headers:headers)。responseJSON{debugPrint中的response(response

Alamofire在将参数格式化为请求url方面做得很好。正如使用.post方法将参数传递给AF request函数一样,您还可以传递参数[string:any]与.get方法的AF请求相同。区别在于.post会将参数放入请求中。body/data vs.get会使用?q=my_search_字符串将参数格式化到url中

大致如下:

Let参数:[string:any]=[“q”:“odesza”,“type”:“track”]
AF.request(.GET,url,参数:params,headers:headers).responseJSON{debugPrint中的response(response

因此我将请求的格式更改为AF.request(url,方法:.GET,参数:params).responseJSON{debugPrint中的response(response)}这允许我运行代码,但是它不起作用,因为我没有我的头。当我将我的头添加到AF.request(url,方法:.get,参数:params,头:头)时它返回到调用中的额外参数“method”。以下内容对我有效,我有包装器API客户端类,但这是alamofire请求行:alamofire.request(requestUrl,method:method,parameters:params,encoding:encoding,headers:header)您是否必须导入某些内容才能使客户端类可用?我的类不会出现这种情况。您看到的当前错误是什么?通过pods,Alamofire.request函数定义为:public func request(url:urlconverable,method:HTTPMethod=.get,parameters:parameters?=nil,encoding:ParameterEncoding=URLEncoding.default,headers:HTTPHeaders?=nil)->DataRequest{调用中的额外参数'method',这仍然与AF.request保持一致(url,method:.get,parameters:params,headers:headers)。我还尝试了AF.request(url,方法:.get,参数:params,编码:JSONEncoding.default,头:头)我也遇到了同样的错误……我尝试将编码更改为encode,因为还有另一个函数以这种方式定义了AF,我不确定。这个错误会比实际代码更大吗?我有alamofire 5.0和xcode 10.1,所以我将请求的格式更改为AF.request(url,方法:.get,参数:params).responseJSON{response in debugPrint(response)}这允许我运行代码,但是它不起作用,因为我没有我的头。当我将我的头添加到AF.request时(url,方法:.get,参数:params,头:头)它返回到调用中的额外参数“method”。以下内容对我有效,我有包装器API客户端类,但这是alamofire请求行:alamofire.request(requestUrl,method:method,parameters:params,encoding:encoding,headers:header)您是否必须导入某些内容才能使客户端类可用?我的类不会出现这种情况。您看到的当前错误是什么?通过pods,Alamofire.request函数定义为:public func request(url:urlconverable,method:HTTPMethod=.get,parameters:parameters?=nil,encoding:ParameterEncoding=URLEncoding.default,headers:HTTPHeaders?=nil)->DataRequest{调用中的额外参数'method',这仍然与AF.request保持一致(url,method:.get,parameters:params,headers:headers)。我还尝试了AF.request(url,方法:.get,参数:params,编码:JSONEncoding.default,头:头)我也遇到了同样的错误……我尝试过将编码改为编码,因为还有另一个函数用这种方式定义了AF,我不确定。这个错误会比实际代码更大吗?我有alamofire 5.0和xcode 10.1