当我尝试使用带有swift 4的alamofire打印json结果时,我得到一个“错误域= kCFErrorDomainCFNetwork Code = 303”

时间:2018-01-18 05:50:30

标签: ios alamofire swift4 xcode9

Alamofire.request("https://www.googleapis.com/youtube/v3/playlists", 
method: .get, parameters: ["part": "snippet", "channelId": 
"UCMztOaBEOOswwu0wHlchkeA", "key": 
"AIzaSyBHzTMlp1FkiIQJxda5UgSunikzfnQWnwQ" ], encoding: 
JSONEncoding.default, headers: nil).downloadProgress(queue: 
DispatchQueue.global(qos: .utility)) { Progress in
        print("progress: \(Progress.fractionCompleted)")

                }
        .validate { request ,response ,data in


            return .success
    }

        .responseJSON { response in
            print(response)
            debugPrint(response)
    }

当我尝试打印响应时,我收到错误“Domain = kCFErrorDomainCFNetwork Code = 303

1 个答案:

答案 0 :(得分:2)

JSONEncoding.default更改为URLEncoding.default

这些参数是定义的here查询参数,因此您应该使用URLEncoding代替JSONEncoding