我正在尝试从快速创建的iPhone应用程序访问开放秘密API(https://www.opensecrets.org/api)。
我正在使用AFNetworking GET请求如下:
func getContributors(congressperson: congressPerson!, success: ([NSDictionary]) -> (), failure: (NSError) -> ()){
let parameters = [
"cid": congressperson.crpId,
"output": "json",
"apikey": opensecretApiKey,
"cycle": "2016"] as NSDictionary
GET("api/?method=candContrib", parameters: parameters, progress: nil, success: { (operation: NSURLSessionDataTask, response: AnyObject?) -> Void in
let results = response!["results"] as! [NSDictionary]
print("here success")
success(results)
}) { (operation: NSURLSessionDataTask?, error: NSError) -> Void in
print("here fail")
failure(error)
}
}
虽然我正在请求输出json,但此代码会导致错误: 请求失败:不可接受的内容类型:text / html
我在这个请求中做错了吗?有人知道如何强迫它以json的形式返回吗?