问题
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