将数据从php发送到我的SWIFT 3

时间:2017-06-26 16:53:03

标签: php swift post

嘿你好我的代码有问题 我有这个问题3天了,我不能自己解决。

抱歉,如果英语那么糟糕

这是我的PHP代码

<?php
// Create connection
$conn = @mysqli_connect('localhost', 'id2066022_oakkozht', 'oakko7596');
 mysqli_select_db($conn, "id2066022_uficondb") or die ("no database");
date_default_timezone_set('Asia/Bangkok');
$timestamp = date('Y-m-d H:i:s');
$numQue=$_POST["numQue"];
$dated=$_POST["dated"];
$return_arr = array();

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
$insertation = "INSERT INTO uficontable (date_timestamp)
        VALUES (CURRENT_TIMESTAMP)";
$selectation = "SELECT * FROM uficontable ORDER BY id DESC LIMIT 1";

    $insertationQuery = mysqli_query($conn, $insertation);
    if (!$insertationQuery) {
        echo "Could not process your information " . mysqli_error();
    } else {
    $selectationQuery = mysqli_query($conn, $selectation);
    while ($data = mysqli_fetch_assoc($selectationQuery))
    {
       $return_arr[] = $data;    
    }
    }
echo json_encode($return_arr);
echo "Connected successfully";

?>

和SWIFT

    func requestPost () {

        let request = NSMutableURLRequest(url: NSURL(string: "https://oakkohost.000webhostapp.com/test.php") as! URL)
        request.httpMethod = "POST"
        let postString = "numQue"

        request.httpBody = postString.data(using: .utf8)
        let task = URLSession.shared.dataTask(with: request as URLRequest) { data, response, error in
            guard let data = data, error == nil else {
                print("error=\(error)")
                return
            }
            let responseString = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
            print("post: \(responseString)")

                    }
        task.resume()
    }
   }

结果是

[{"id":"147","date_timestamp":"2017-06-26 16:42:16"}]

问题是我想在Swift Code中使用我的标签id的结果 我怎么用这个?

感谢您的回答

0 个答案:

没有答案