Swift TRON Content Type HeaderBuilder Syntax

断了今生、忘了曾经 提交于 2019-12-11 06:14:17

问题


I'm using TRON to access an api based with ruby on rails, I sense that my problem is because the header does not have the correct information. I've been playing with the HeaderBuilder syntax from TRON but not able to really see what the syntax needs to be. My rails error is when trying to get data from a specific controller action

[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)

In xcode, I am using a rest type controller for getting 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
}

I have added the headerbuilder call in the method, but I think I also need content type. I've spent a day on this already, needing to figure it out to not miss deadlines :( thanks in advance for any help

来源:https://stackoverflow.com/questions/43477807/swift-tron-content-type-headerbuilder-syntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!