1

我想使用RxAlamofire进行 post 调用,它提供了函数 requestJson,它需要两个参数 类型 get 或 post 和 url但是没有参数来传递 post json body如何做到以下是我的代码

 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)
4

1 回答 1

0

其实其他参数都包含在requestJson的定义中,只是有默认参数而已。所以你可以放心地说:

RxAlamofire.requestJSON(.post,
                        url,
                        parameters: ["param1": "value1"],
                        encoding: JSONEncoding.default,
                        headers: nil)
于 2019-05-31T15:55:35.917 回答