0
我正在使用AlamoFire在Google Cloud Prediction中对我的某个模型进行POST查询。无论何时我发送请求,我都会返回一个错误,指出:此API不支持解析表单编码输入。
经过一番研究,我发现我需要将我的Content-Type HTTP标头设置为“application/json”。希望你能在找到我的请求时找到我错过的东西。这里是我的代码:AlamoFire请求Google Cloud Prediction API iOS解析错误
let parameters = [
"access_token" : accessToken,
"input": [
"csvInstance": [
"This is very positive"
]
]
]
Alamofire.Manager.sharedInstance.session.configuration
.HTTPAdditionalHeaders?.updateValue("application/json",
forKey: "Accept")
Alamofire.Manager.sharedInstance.session.configuration
.HTTPAdditionalHeaders?.updateValue("application/json",
forKey: "Content-Type")
Alamofire.request(.POST, "https://www.googleapis.com/prediction/v1.6/projects/mailanalysis-1378/trainedmodels/10kTweetData/predict", parameters: parameters).responseJSON { (response) in
if let JSON = response.result.value {
print("JSON: \(JSON)")
//print("refresh token = " + auth.accessToken)
}
}
Alamofire为您处理'应用/ json'一旦你在方法'requestJSON'中使用JSON序列化器,你应该使用它而不是正常的请求 –
@VictorSigler你是什么意思的方法requestJSON?我如何称呼它?我似乎无法将其作为Alamofire的方法之一 – user3798602
抱歉,我的错误是['responseJSON'](https://github.com/Alamofire/Alamofire#response-json-handler) –