gpt4 book ai didi

ios - 如何使用 RxAlamofire 在帖子正文中传递 json 进行帖子调用

转载 作者:行者123 更新时间:2023-11-28 07:27:12 25 4
gpt4 key购买 nike

我想使用 RxAlamofire 进行调用,它提供了函数 requestJson 需要两个参数 type get or post and 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)

最佳答案

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

RxAlamofire.requestJSON(.post,
url,
parameters: ["param1": "value1"],
encoding: JSONEncoding.default,
headers: nil)

关于ios - 如何使用 RxAlamofire 在帖子正文中传递 json 进行帖子调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56227364/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com