如何在 alamofire 中分离请求 body?

How to separate request body in alamofire?

我使用 YouTube 直播 API。
它需要 http headers,参数,请求 body.

参数是必需的查询字符串格式。
请求 body 需要 json 格式。

在 Alamofire 中只有参数,header。
如何将请求body和参数分开??

到目前为止,我都是这样使用的。

let params: [String: Any] = [
    "part": "snippet, status", // part is parameter
    "snippet": ["title": "hhzz", // snippet is request body
                "scheduledStartTime": "2018-12-18T13:00:0Z"],
    "status": ["privacyStatus": "public"] // status is request body
]

Alamofire.request(url, method: .post, parameters: params, encoding: URLEncoding.queryString, headers: header).responseJSON { (response) in
    if let response = response.result.value {
        print(response)
    }
}

但是,这个请求总是失败。因为服务器识别请求 body=nil.
Alamofire 请求方法没有请求 body.
我在哪里可以输入请求 body?
或如何分离请求 body??

来自Youtube documentation它需要json body,所以你需要使用JSON编码并且需要在请求中添加url参数url.

let url = "https://www.googleapis.com/youtube/v3/liveBroadcasts?part=snippet,status"
Alamofire.request(url, method: .post, parameters: params, encoding: JSONEncoding.default, headers: header).responseJSON { (response) in
    if let response = response.result.value {
        print(response)
    }
}