Search code examples
swiftswift4rx-swiftrxalamofire

RxAlamofire make post call with json body


I want to make post call using RxAlamofire not able to find any method to do so

tried using requestJSON method but there is no paramter to pass post json in

 RxAlamofire.requestJSON(.post, url)

how to make post call and pass json data to post call in RxAlamofire


Solution

  • Use following code

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