0
içinden nasıl alabilirim? Barkodu tarayan ve sunucudan bazı JSON verilerini almak için http dinlenme çağrısı kullanarak bir yöntem yazmaya çalışıyorum. Alamofire şimdi çalışmıyor ve birçok farklı yol denedim. önemli bir hatayla: JSON verilerini swift2.0, xcode7.3
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()
bir hata mesajı alıyorum:
let httpResponse = response as! NSHTTPURLResponse
, ek olarak şemasını eklemek gerek için (örneğin 'http: //' veya 'https: //'), sadece var varsayarak http: // ', daha sonra http://stackoverflow.com/questions/31254725/transport-security-has-blocked-a-cleartext-http/ adresinde açıklandığı gibi alanınızı 'NSAppTransportSecurity' alanına eklemeniz gerekebilir. 31254874 # 31254874. – Rob