Swift TRON内容类型HeaderBuilder语法

时间:2017-04-18 16:43:36

标签: ruby-on-rails json swift api alamofire

我正在使用TRON来访问基于ruby on rails的api,我觉得我的问题是因为标题没有正确的信息。我一直在使用TRON的HeaderBuilder语法,但却无法真正看到语法需要的内容。我的rails错误是在尝试从特定控制器操作中获取数据时

[active_model_serializers] Rendered ActiveModel::Serializer::Null with 
Hash (0.25ms)
Filter chain halted as :ensure_valid_accept_media_type rendered or 
redirected
Completed 406 Not Acceptable in 61ms (Views: 30.0ms | ActiveRecord: 
 2.7ms | Solr: 0.0ms)

在xcode中,我使用rest类型控制器来获取json

public class DataController {
static let tron = TRON(baseURL: GlobalVariables().baseURL)

class Fetched: JSONDecodable {
    let response: JSON
    required init(json: JSON) throws {
        let response = json
        self.response = response
    }
}

class FetchFailed: JSONDecodable {
    let response: JSON
    required init(json: JSON) throws {
        let response = json
        self.response = response
    }
}

func FetchData(url_param: String) {
    let FetchRequest: APIRequest<Fetched, FetchFailed> = DataController.tron.request(url_param)
    FetchRequest.perform(withSuccess: { (Fetched) in
        print("Success", Fetched)
    }) { (err) in
        print("Error")
    }
}

func Get(parameters: [String:Any], path: String) -> APIRequest<Fetched, FetchFailed> {
    let request: APIRequest<Fetched, FetchFailed> = DataController.tron.request(path)
    request.parameters = parameters

    request.headerBuilder.headers(forAuthorizationRequirement: AuthorizationRequirement.allowed, including: ["Accept":"application/vnd.api+json"])
    return request
}

我在方法中添加了headerbuilder调用,但我认为我还需要内容类型。我已经在这上面花了一天时间,需要弄清楚不要错过最后期限:(事先感谢任何帮助

0 个答案:

没有答案