0
バーコードをスキャンし、http rest callを使用してサーバーからJSONデータを取得するメソッドを作成しようとしています。 Alamofireは今は動作しません。私はさまざまな方法で試しました。 致命的なエラー: swift2.0、xcode7.3でhttpリクエストからJSONデータを取得する方法
let getEndpoint: String = "45.55.63.218:8080/food?foodidentifier=\(code)"
let requestURL: NSURL = NSURL(string: getEndpoint)!
let urlRequest: NSMutableURLRequest = NSMutableURLRequest(URL: requestURL)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(urlRequest) {
(data, response, error) -> Void in
let httpResponse = response as! NSHTTPURLResponse
let statusCode = httpResponse.statusCode
if (statusCode == 200) {
print("Everyone is fine, file downloaded successfully.")
do{
//let json = try NSJSONSerialization.JSONObjectWithData(data!, options:.AllowFragments)
}catch {
print("Error with Json: \(error)")
}
}
}
task.resume()
が、私はエラーメッセージが表示されます:
let httpResponse = response as! NSHTTPURLResponse
をところで、スキーム(例えば、 'ます。http://'や 'https://での')を追加する必要に加えて、それが唯一だと仮定すると'http://'であれば、http://stackoverflow.com/questions/31254725/transport-security-has-blocked-a-cleartext-http/に記載されているように、ドメインをNSAppTransportSecurityに追加する必要があるかもしれません。 31254874#31254874 – Rob