0

我想使用 RxAlamofire 进行后期调用,但找不到任何方法

尝试使用 requestJSON 方法,但没有参数可以传递 post json

 RxAlamofire.requestJSON(.post, url)

如何在 RxAlamofire 中进行 post call 并将 json 数据传递给 post call

4

3 回答 3

1

使用以下代码

  var request = URLRequest(url: URL(string: "https://some_url")!)
    //Following code to pass post json 
    request.httpBody = json
    request.httpMethod = "POST"
    request.setValue("application/json", forHTTPHeaderField: "Content-Type")
    RxAlamofire.request(request as URLRequestConvertible).responseJSON().asObservable()
于 2019-05-26T08:59:31.797 回答
0

将此函数与适当的参数编码一起使用

public func urlRequest(_ method: Alamofire.HTTPMethod,
                   _ url: URLConvertible,
                   parameters: [String: Any]? = nil,
                   encoding: ParameterEncoding = URLEncoding.default,
                   headers: [String: String]? = nil)
于 2019-05-21T06:48:41.510 回答
-1

使用 jsonEncoding

RxAlamofire.requestJSON(.post, url, encode: JsonEncoding.default)

对我有用~

于 2020-08-19T07:08:53.160 回答