swift - Alamofire can't get request with php -


i have got swift 4 code

let par: parameters = [                           "usn":"murad",                           "password":"monkey"                       ] alamofire.request("http://www.web.com/ajax/logreg.php",method: .post,parameters:par,encoding: urlencoding.httpbody).response { response in      if let data = response.data, let utf8text = string(data: data, encoding: .utf8) {        print("data: \(utf8text)")    } } 

and php code

print_r($_post); 

now supposed code print

array(    "usn":"murad",    "password":"monkey",     ) 

but instead prints

array (     [(componenttuple_0)] => (componenttuple.1) ) 

try code

   let par: parameters = [                 "usn":"murad",                 "password":"monkey"             ]      alamofire.request("http://www.web.com/ajax/logreg.php", method: .post, parameters: par as? [string : anyobject], encoding: jsonencoding.default).responsejson { response in             switch response.result {             case .success(let json):                 //                    print("success json: \(json)")                 if let response = json as? nsmutabledictionary         {             callback(response,nil)         }         else if let response = json2 as? nsdictionary         {             callback(response,nil)         }         else if json2 nsarray         {           }         else if ((json as? string) != nil)         {              let userdic : [string : string] = ["quatid":json as! string]             print(userdic)             callback(userdic nsdictionary?,nil)      }                  break              case .failure(let error):                 print("request failed error: \(error)")                 callback(response.result.value as? nsmutabledictionary,error nserror?)                 break             }             }             .responsestring { response in                 print("response string: \(response.result.value)")         } 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -