Alamofire,额外的争论'方法'在电话中

时间:2017-12-21 03:42:33

标签: alamofire ios11 swift4 xcode9

我有一些答案没有运气,我得到了这个错误"额外的争论'方法'在电话"并且指向" .get",但如果我删除" headers:标题为? [String:Any]"有用。请帮忙

let urlParams:[String : Any] = [
        "target": target,
        "q": textToTranslate,
        "key": GOOGLE_CLOUD_API_KEY,
        "source": source]

    let headers:[String : Any] = ["Content-Type": "application/json",
                                  "X-Ios-Bundle-Identifier": Bundle.main.bundleIdentifier as Any]

    // Fetch Request
    let urlString = TRANSLATE_API

    Alamofire.request(urlString, method : .get, parameters : urlParams as? [String: Any], encoding : JSONEncoding.default , headers : headers as? [String: Any]).responseJSON(completionHandler: { (response:DataResponse<Any>) in

    })

enter image description here

1 个答案:

答案 0 :(得分:0)

我将标题:[String:Any]更改为标题:[String:String]

let bundleIdentifier = Bundle.main.bundleIdentifier!
    let headers:[String : String] = ["Content-Type": "application/json", "X-Ios-Bundle-Identifier": bundleIdentifier]