我想使用RxAlamofire进行post调用,但找不到任何方法。
尝试使用requestJSON方法,但没有参数来传递后置json
RxAlamofire.requestJSON(.post, url)如何在RxAlamofire中进行post调用并将json数据传递给post调用
发布于 2019-05-26 08:59:31
使用下列代码
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-21 06:48:41
在适当的参数和编码条件下使用此函数
public func urlRequest(_ method: Alamofire.HTTPMethod,
_ url: URLConvertible,
parameters: [String: Any]? = nil,
encoding: ParameterEncoding = URLEncoding.default,
headers: [String: String]? = nil)发布于 2022-05-07 01:22:50
amodkanthe的解决方案有效。但它的回报价值并不是很好。所以我把它改了一点
var request = URLRequest(url: URL(string: "https://some_url")!)
request.httpBody = jsonData // jsonData is a Data type
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type") // this line is important
RxAlamofire.requestJSON() //=> returns a Observable<(HttpURLResponse, Any)>, the `Any` type is actually a dictionary附注:我使用的版本是RxAlamofire(6.1.1)
https://stackoverflow.com/questions/56232506
复制相似问题