Mobil

Web service JSON POST Swift

let request = NSMutableURLRequest(url: URL(string: "http://muratbayri.com")!)
            request.httpMethod = "POST"
            let postString = "id=(idobject)"
            
            request.httpBody = postString.data(using: .utf8)
            
            let task = URLSession.shared.dataTask(with: request as URLRequest) { data, response, error in
                guard error == nil && data != nil else {
                    print("error=(String(describing: error))")
                    return
                }
                
                if let httpStatus = response as? HTTPURLResponse , httpStatus.statusCode != 200 {
                    print("statusCode should be 200, but is (httpStatus.statusCode)")
                    print("response = (String(describing: response))")
                }
                
                let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)!
                
                
            }
            
            
            task.resume()