2016-11-02 21 views
0

私は私のサーバー上のPHPスクリプトを持っています、私は私のアプリからデータを投稿しようとしています。それがどんなアイデアなのか?何も私のPHPスクリプトに投稿されていません

スウィフト

let url: NSURL = NSURL(string: "https://xxxxxx.com/myFile.php")! 
    let request:NSMutableURLRequest = NSMutableURLRequest(url: url as URL) 
    let bodyData = "username=\(username.text)&password=\(password.text)" 
    request.httpMethod = "POST" 
    request.httpBody = bodyData.data(using: String.Encoding.utf8); 
    request.setValue("application/x-www-form-urlencoded; charset=utf-8", forHTTPHeaderField: "Content-Type") 
    NSURLConnection.sendAsynchronousRequest(request as URLRequest, queue: OperationQueue.main) 
    { 
     (response, data, error) in 
     let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue) 
     // 
     print("response \(responseString)") 

    } 

PHP

print_r($_POST); //prints: ([username] => xxxxxx [password] => yyyyyy) 
json_encode($postVarUser); 
json_encode($postVarPass); 

答えて

1

それはエコーの問題($ postUser)であることができ、 json_encode($ postUser)を使用してください。

+0

また、print_rは、ポスト変数を出力しませんか? – joethemow

+0

すべてのポスト変数を配列に入れてエンコードする –

関連する問題