Hi I have a problem like this, I'm writing a swift application 3 that communicates with a php file on a remote server, my problem is that when I send the parameters in post to the http page, the server receives the parameters incorrectly , In the request to the php file comes a constructed string like this: Optional ("prova@email.it") , Should theoretically only arrive: prova@email.it, how do I fix this problem? Placed below both the php and swift codes
SWIFT CODE:
import Foundation
class User{
/
let URL_SAVE_TEAM = "http://mylink/myfile.php"
var email=""
var password=""
func PrintValue(){
/
/
}
func Login() -> String{
var ris="";
/
guard let requestURL = URL(string: URL_SAVE_TEAM) else { return "no" }
/
var request = URLRequest(url: requestURL)
/
request.httpMethod = "POST"
/
/
let postParameters = "email=\(email)&password=\(password)"
/
request.httpBody = postParameters.data(using: .utf8)
/
let session = URLSession.shared
let task = session.dataTask(with: request) {
data, response, error in
guard error == nil else {
print("error is \(error!.localizedDescription)")
return
}
guard let data = data else {
print("No data was returned by the request!")
return
}
/
do {
/
let myJSON = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? Dictionary<String, String?>
/
guard let parseJSON = myJSON, let msg = parseJSON["message"] as? String else {
print("Error parsing data")
return
}
/
print(msg)
ris=msg;
} catch {
print(error)
}
}
/
task.resume()
return ris;
}
}PHP CODE:
<?php
include 'user.php';
header('Content-Type: application/json');
$email= $_POST['email'];
$password = $_POST['password'];
$ris['message']="";
$user = new User();
//procedo con il login
if($user->login($email,$password,"MOBILE")==true){
$ris['message']="yes";
}
else{
$ris['message']="no $email";
}
echo json_encode($ris);
?>