迅速的Alamofire发布“通话中的额外参数”

时间:2018-07-03 15:34:05

标签: swift alamofire

我想将一些xml发布到URL。这是我的代码:

func post(){
    var data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Devices><Device><ID>EZR0114AF</ID><HEATAREA nr=\"4\"><T_TARGET>17.0</T_TARGET></HEATAREA></Device></Devices>"

    Alamofire.request(urlPost, .post, parameters: data, encoding: .utf8, headers: nil).response { (response) in
        print(response.data)
        print(response.error)
        print(response.response)
    }
}

但是我收到语法错误:Extra argument in call。我不知道缺少了什么,我尝试了很多,但没有任何效果。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

尝试将语法更改为

 let urlString = "XXXXXXXXX"

        Alamofire.request(urlString, method: .post, parameters: ["id": "1,2,3,4"] ,encoding: JSONEncoding.default, headers: nil).responseString {

            response in
            switch response.result {
            case .success(let responseString1):
                print("the response is: \(responseString1)")

                break
            case .failure(let error):

                print("The error is: \(error)")
            }
        }