【发布时间】:2020-02-29 19:21:54
【问题描述】:
我在使用 Swift 的 Xcode 中使用 URLSession 的自定义 Api 的 http 请求存在问题。这是我的代码:
let forecast = self.forecastList[forecastIndex]
let url : URL = URL(string: "https:laundryireland.tk/getForecast?pwd=\(self.CustomApiKey)&temp=\(forecast.temp)&hum=\(forecast.humidity)&pres=\(forecast.pressure)&weat=\(forecast.weather)&wind=\(forecast.windspeed)")!
let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
guard let data = data else { return }
do {
let scores = try JSONDecoder().decode(Scores.self, from: data)
// ...
} catch {
print("ops")
}
}
task.resume()
这段代码已经在第三行抛出了错误:
2019-11-04 12:53:26.701212+0000 DIYP[2554:1119528] [] tcp_input [C6.1:3] flags=[R.] seq=0, ack=2949324956, win=0 state=SYN_SENT rcv_nxt=0, snd_una=2949324955
2019-11-04 12:53:26.702757+0000 DIYP[2554:1119528] Connection 6: received failure notification
2019-11-04 12:53:26.702843+0000 DIYP[2554:1119528] Connection 6: failed to connect 1:61, reason -1
2019-11-04 12:53:26.702897+0000 DIYP[2554:1119528] Connection 6: encountered error(1:61)
2019-11-04 12:53:26.706142+0000 DIYP[2554:1119528] Task <46A61430-630E-48F8-B121-82B1C7BEE5DF>.<2> HTTP load failed, 0/0 bytes (error code: -1004 [1:61])
我在这里看到:TIC TCP Conn Failed [4:0x604000360300]: 1:61 Err(61) <1> HTTP load failed (error code: -1004 错误 1004 与无法解析主机的设备有关,但这对我来说似乎很奇怪,因为我的 URL 位于可访问的远程服务器上运行的注册域上来自任何地方(只需在浏览器中输入:http://laundryireland.tk 即可查看它是否正常工作)。
我该如何解决这个问题?
【问题讨论】:
-
会不会是 SSL 证书问题?我读到苹果只支持
https,对吗?
标签: swift xcode urlsession