首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Post体中使用RxAlamofire传递json进行post调用

如何在Post体中使用RxAlamofire传递json进行post调用
EN

Stack Overflow用户
提问于 2019-05-20 19:55:31
回答 1查看 369关注 0票数 1

我想用RxAlamofire进行post调用,它提供了函数 requestJson,它需要两个参数: get或post和url< code >E 29,但是有E 110没有参数传递post json bodyE 211如何执行下面的代码

代码语言:javascript
复制
 var components = URLComponents(string: url)!
    components.setQueryItems(with: param)
    let url = components.url!
    print("\(url)")

    RxAlamofire.requestJSON(.post, url)
        .subscribe(onNext: { [weak self] (r, json) in
            if let jsonResult = JSON(json) as? JSON {
                if let cartResult = FoodCartResult(jsonResult) as? FoodCartResult {
                    self?.delegate?.showCart(cartresult: cartResult)
                }
            }

            }, onError: {  [weak self] (error) in
                print(error.localizedDescription)
                self?.delegate?.onError()
            },onCompleted: {})
        .disposed(by: disposeBag)
EN

回答 1

Stack Overflow用户

发布于 2019-05-31 15:55:35

实际上,其他参数都包含在requestJson的定义中,它们只有默认参数。所以你可以有把握地说:

代码语言:javascript
复制
RxAlamofire.requestJSON(.post,
                        url,
                        parameters: ["param1": "value1"],
                        encoding: JSONEncoding.default,
                        headers: nil)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56227364

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档