swift中的HTTP请求不起作用 [英] HTTP Request in swift not working
本文介绍了swift中的HTTP请求不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在努力学习如何在 Swift 中使用 API.作为一个很好的第一次测试,我想我会点击 itunes API 并只返回一些搜索结果.我在操场上使用以下代码.我没有收到任何错误,但我的 println 没有输出任何内容.有人知道怎么回事吗?
I'm trying to learn about working with APIs in Swift. As a good first test, I figured I'd hit the itunes API and just return some search results. I'm in playground using the following code. I don't get any errors, but my println isn't outputting anything. Anyone know what's wrong?
谢谢!
import UIKit
import XCPlayground
XCPSetExecutionShouldContinueIndefinitely()
let url = NSURL(string: "https://itunes.apple.com/lookup?id=909253")
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in
println(NSString(data: data, encoding: NSUTF8StringEncoding))
}
task.resume()
推荐答案
尝试添加这行代码:
URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
这篇关于swift中的HTTP请求不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文