'Getting NSDebugDescription=Invalid value around character 0. When posting request using PHP with Swift

I am getting an error when i try to post my data through php with swift that says Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}

What does this error mean? I resolved other issues related to using PHP with swift but i am still getting this error.

How can i fix this error?

here is my code:

let ADD_PROP_URL = "https://example.com/WebService/api/addProperty.php"

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    
    @IBAction func addProperty(_ sender: Any) {
        
        let requestURL = NSURL(string: ADD_PROP_URL)
            
        var request = URLRequest(url: requestURL! as URL)
            
        request.httpMethod = "POST"
        request.addValue("application/json", forHTTPHeaderField: "Content-Type")
        
        let propName = propName.text
        let propPrice = propPrice.text
        let propBed = propBedrooms.text
        let propLoc = propLoc.text
    
        let postParameters = "name="+propName!+"&price="+propPrice!+"&bedrooms="+propBed!+"&location="+propLoc!;
                
        request.httpBody = postParameters.data(using: String.Encoding.utf8)
                
        let task = URLSession.shared.dataTask(with: request){
            data, response, error in
                    
            if error != nil{
                print("error is \(error)")
                return;
            }
                
            do {
                        
                let myJSON =  try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? NSDictionary
            
                if let parseJSON = myJSON {
                    var msg : String!
                    msg = parseJSON["message"] as! String?
                    print(msg)
                    print(response)
                    print(data)
                }
            } catch {
                print(error)
                print(response)
                print(data)
        }
                    
    }
               
    task.resume()
                
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source