swiftでhttp通信

info.plistに追加します。

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>http://hpscript.com/</key>
            <dict>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <false/>
            </dict>
        </dict>
    </dict>

php

$response = array();

if($_SERVER['REQUEST_METHOD'] == 'POST'){
	$teamName = $_POST['name'];
	$member = $_POST['old'];

	$response['api'] = "succeeded";
	$response['member'] = $member . " years old!";
	echo json_encode($response);
}

xcode console
っキタキタキタ!!!!!!!!!!!!!!!!!!!!!!!!

今回、php側はjsonで返してますが、mysqlへのinsert, fetchResultもできますね。iOSの光が見えてきた。