我想使用 RxAlamofire 进行后期调用,但找不到任何方法
尝试使用 requestJSON 方法,但没有参数可以传递 post json
RxAlamofire.requestJSON(.post, url)
如何在 RxAlamofire 中进行 post call 并将 json 数据传递给 post call
我想使用 RxAlamofire 进行后期调用,但找不到任何方法
尝试使用 requestJSON 方法,但没有参数可以传递 post json
RxAlamofire.requestJSON(.post, url)
如何在 RxAlamofire 中进行 post call 并将 json 数据传递给 post call
使用以下代码
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()
将此函数与适当的参数编码一起使用
public func urlRequest(_ method: Alamofire.HTTPMethod,
_ url: URLConvertible,
parameters: [String: Any]? = nil,
encoding: ParameterEncoding = URLEncoding.default,
headers: [String: String]? = nil)
使用 jsonEncoding
RxAlamofire.requestJSON(.post, url, encode: JsonEncoding.default)
对我有用~