-1
私はWebページに「ログイン」するいくつかの行を持っており、内容を取り出してコンソールに出力しますが、「タスク」から結果を得る方法を理解することはできません。後でコード内で使用してください。Swiftにログインした後のURLの内容を返しますか?
let request = NSMutableURLRequest(URL: NSURL(string: "http://localhost:8888/mobilelogin.php")!)
request.HTTPMethod = "POST"
let username = email_input.text;
let password = password_input.text;
var postString = "username="
postString += username!
postString += "&password="
postString += password!
print(postString);
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
print(request.HTTPBody);
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data, response, error in guard error == nil && data != nil
else {
// check for fundamental networking error
print("error=\(error)")
return
}
if let httpStatus = response as? NSHTTPURLResponse where httpStatus.statusCode != 200 {
// check for http errors
print("statusCode should be 200, but is \(httpStatus.statusCode)")
print("response = \(response)")
return
}
let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)!
print("responseString = \(responseString)");
return
}
print("This is the task string")
task.resume()
ありがとうございます! – inigomontoya333
変数として取得する方法はありますか?ラベルを設定するには? – inigomontoya333
ようこそ。 [this](http://stackoverflow.com/help/someone-answers)を忘れないでください。あなたの変数のために:もちろん! :)あなたは何をしたいのですか? 'print(response)'の代わりに 'getData'では、必要に応じてラベルなどのためにレスポンスを使います。 – Moritz