Search code examples
swiftalamofirepostman

How to POST request with raw param with JSON Data Alamofire


I am trying to call API that param is accept Raw value as JSON formate. I am searching but can't get satisfied ans.

Reference Image Any one can help me.

Thanks in Advance


Solution

  • i am try this code and working fine for me.

     let url = "Your URL"
    
            let JsonString = "Yout JSON Data" //  Ex.:-  "{\"action\": \"fetch-data\"}"
            var request = URLRequest(url: URL(string: url)!)
            request.httpMethod = HTTPMethod.post.rawValue
            request.setValue("application/json", forHTTPHeaderField: "Content-Type")
    
            let pjson = JsonString
            let data = (pjson.data(using: .utf8))! as Data
    
            request.httpBody = data
    
            Alamofire.request(request).responseJSON { (response) in
    
                print(response)
    
            }