Home > AI > Language > PHP >

$_GET

test 1: request on browser url

// server.php
<?php
echo $_GET['token'];
echo "goood";
?>

// request link
// http://ios.jobyme88.com/KidsLearnHindi/server.php?token=aa

test 2: curl from command line

curl 'http://ios.jobyme88.com/KidsLearnHindi/connect-to-server.php?token="aa"'

test 3: ios

// send to server
let url = URL(string: "http://www.ios.jobyme88.com/KidsLearnHindi/server.php?token=\(data.deviceToken)")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
let task = URLSession.shared.dataTask(with: request) { data, response, error in

    // check error
    if let error = error {
        print ("error: \(error)")
        return
    }

    // check response
    guard let response = response as? HTTPURLResponse,
                    (200...299).contains(response.statusCode) else {
        print ("server error")
        return
     }

    // print data from server
    guard let data = data else {
        print("no data")
        return
    }

    let dataString = String(data: data, encoding: .utf8)
    print ("got data: \(dataString)")
}
task.resume()

server.php

echo $_GET['token'];
echo "goood";

Leave a Reply