Using manager.request with POST

前端 未结 1 1649
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-22 01:34

I want to send a POST request with Alamofire SessionManager.

I read the documentation on https://github.com/Alamofire/Alamofire/blob/maste

相关标签:
1条回答
  • 2020-12-22 02:23

    You need conform URLRequest with your parameters in body as Data

    This code can help you

        var request = URLRequest(url: urlString!)
        request.httpMethod = "POST"
        request.setValue("application/json", forHTTPHeaderField: "Content-Type")
    
        request.httpBody = try! JSONSerialization.data(withJSONObject: parameters)
    
        manager.request(request)
               .responseJSON { response in
                    fulfill(response)
            }
    

    Hope this helps

    0 讨论(0)
提交回复
热议问题