ios - 如何在 AlamofireXMLRPC 请求上设置 HTTP header 字段?

标签 ios swift http-headers alamofire xml-rpc

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

    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

最佳答案

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

enter image description here

示例:

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

或者

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

enter image description here

关于ios - 如何在 AlamofireXMLRPC 请求上设置 HTTP header 字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50840265/

相关文章:

iphone - 当使用泄漏进行分析时,NSURLConnection 会吸收内存

swift - 使用 Swift 在 UIActionsheet 中添加日期选择器

java - is not abstract and does not override abstract method 错误

java - 如何通过 post man post 请求在 header 中传递对象?

ios - 如何在 Swift 中的自定义键盘中启用表情符号

ios - Index.path 没有返回正确的索引

ios - 通过 Swift 中的标签访问 UITableViewCell 内的不同 View

ios - 如何在Data ViewController的viewDidLoad中加载数据,而不减慢uipageViewController滚动速度?

javascript - X-Frame-Options Deny 根本不起作用

ios - 开启/关闭iCloud时迁移数据