2017-12-07 9 views
0

私はサインインできませんし、コンソール上でプリントしようとしているときにレスポンスを得られません。今すぐサインアップすることができませんでしイム:サインイン文字列のレスポンスを得るには

var request = URLRequest(url: URL(string: "http://fundedindia.org/funded/Doner_Registration.php")!) 
    request.httpMethod = "POST" 
    let postString = "Email=\(textfieldemail.text!)&Password=\(textfieldpassword.text!)&MobileNo=\(textfieldmobile.text!)&UserType=\(butname)&LoginType=Normal" 
    request.httpBody = postString.data(using: .utf8) 
    let task = URLSession.shared.dataTask(with: request) { data, response, error in 
     guard let data = data, error == nil else {             // check for fundamental networking error 
      print("error=\(String(describing: error))") 
      return 
     } 

     if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 {   // check for http errors 
      print("statusCode should be 200, but is \(httpStatus.statusCode)") 
      print("response = \(String(describing: response))") 

     } 

     let json = try! JSONSerialization.jsonObject(with: data, options: []) as! NSDictionary 
     let msg = json.value(forKey: "message") as! NSString! 

     self.activityIndi.stopAnimating() 
     self.activityIndi.hidesWhenStopped = true 
     let alert : UIAlertView = UIAlertView(title: "Alert box!", message: "\(msg!).",delegate: nil, cancelButtonTitle: "OK") 
     alert.show() 
    } 
    task.resume() 
} 
+0

エラーメッセージもWebサーバーレスポンスも含まれますか? –

答えて

0

私は

var request = URLRequest(url: URL(string: "http://fundedindia.org/funded/Doner_Registration.php")!) 
    request.httpMethod = "POST" 
    let email: String = "[email protected]" 
    let password: String = "12345678" 
    let mobileNo: String = "9599904029" 
    let butname: String = "1" 
    let postString = "Email=\(email)&Password=\(password)&MobileNo=\(mobileNo)&UserType=\(butname)&LoginType=Normal" 
    request.httpBody = postString.data(using: .utf8) 
    let task = URLSession.shared.dataTask(with: request) { data, response, error in 
     guard let data = data, error == nil else {             // check for fundamental networking error 
      print("error=\(String(describing: error))") 
      return 
     } 

     if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 {   // check for http errors 
      print("statusCode should be 200, but is \(httpStatus.statusCode)") 
      print("response = \(String(describing: response))") 

     } 

     let json = try! JSONSerialization.jsonObject(with: data, options: []) as! NSDictionary 
     let msg = json.value(forKey: "message") as! NSString! 

     let alert : UIAlertView = UIAlertView(title: "Alert box!", message: "\(msg!).",delegate: nil, cancelButtonTitle: "OK") 
     alert.show() 
    } 
    task.resume() 

サンプル入力でコードを実行しようとしたそのresponceの状態が正しくない

、バックエンドの開発者と入力し、URLを確認してください。

response = Optional(<NSHTTPURLResponse: 0x604000425fe0> { URL: http://fundedindia.org/funded/Doner_Registration.php } { status code: 500, headers { 
"Cache-Control" = private; 
"Content-Length" = 5759; 
"Content-Type" = "text/html; charset=utf-8"; 
Date = "Thu, 07 Dec 2017 08:58:40 GMT"; 
Server = "Microsoft-IIS/8.0"; 
"X-Powered-By" = "ASP.NET"; 
"X-Powered-By-Plesk" = PleskWin; 

}})

"状態コード500" 成功200であるべきです。

+0

どうして私はそれを申し訳なく置くべきですか?私は答えを得ていませんでした –

+0

okありがとうございました。本当にありがとう –

関連する問題