如何在AlamofireXMLRPC请求上设置HTTP标头字段?

时间:2018-06-13 14:51:55

标签: ios swift http-headers alamofire xml-rpc

我正在尝试在我的请求中设置HTTP标头字段:

    var params = [OdooAuth.db, OdooAuth.uid, OdooAuth.password!,"product.pricelist","search_read", [[]],["fields":["id"]] ] as [Any]
    let request = AlamofireXMLRPC.request(OdooAuth.host2!, methodName: "execute_kw", parameters: params )
    request.request?.addValue("value", forHTTPHeaderField: "HTTP_USER_AGENT")

但是当我写这个时,会发生错误:

Cannot use mutating member on immutable value: 'request' is a get-only property

我使用的是Swift4和this library

1 个答案:

答案 0 :(得分:0)

AlamofireXMLRPC提供了一个带有可选标头字典的请求方法版本。你可以使用它。

enter image description here

示例:

// Usage: 
let request = AlamofireXMLRPC.request(OdooAuth.host2!, methodName: "execute_kw", parameters: params, headers: ["HTTP_USER_AGENT": "value"])

OR

正如文档所述,您可以实施XMLRPCRequestConvertible协议来创建自定义请求。

enter image description here