【发布时间】:2018-12-27 22:11:12
【问题描述】:
从网站获取 JSON 时出现错误。我猜该网站阻止我获取数据。我该如何解决?
import UIKit
import Alamofire
import SwiftyJSON
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=SH600004&begin=1531842004299&period=day&type=before&count=-142&indicator=kline,ma,macd,kdj,boll,rsi,wr,bias,cci,psy")
var urlRequest = URLRequest(url: url)
let manager = Alamofire.SessionManager.default
manager.request(url).responseJSON { (dataResponse) in
do {
if dataResponse.data != nil {
let json = try JSON(data: dataResponse.data!)
print(json.description)
}
} catch {
print("Error: trying to convert data to JSON2")
print(error)
completionHandler(nil, error)
}
}
}
}
但我在下面遇到错误:
{
"error_code" : "400016",
"error_uri" : "\/v5\/stock\/chart\/kline.json",
"error_description" : "Encountered an error, please refresh the page or re-login and try again"
}
【问题讨论】:
-
我认为您的错误与您的代码无关,我怀疑您发送到网站的参数不正确或无效
标签: json swift http cookies header