这是我的端点的外观:
extension MyEndpoint: TargetType {
var baseURL: NSURL { return NSURL(string: "http://10.0.1.13:5000")! }
var path: String {
switch self {
case .SearchForNodes(_, _, _):
return "/api/search/node/"
case .CreateHistoricalEvent(_):
return "/api/node/historicalevent/"
}
}
var method: Moya.Method {
switch self {
case .SearchForNodes(_, _, _):
return .GET
case .CreateHistoricalEvent(_):
return .POST
}
}
var parameters: [String: AnyObject]? {
switch self {
case .SearchForNodes(let startsWith, let page, let pageSize):
return ["startsWith": startsWith, "page": page, "pageSize": pageSize]
case .CreateHistoricalEvent(let title):
return ["Title": title]
}
}
var parameterEncoding: Moya.ParameterEncoding {
switch self {
case .CreateHistoricalEvent:
return ParameterEncoding.Json
default:
return ParameterEncoding.URL
}
}
}
现在我想让我的 CreateHistoricalEvent 方法将其参数作为 JSON 发布到请求正文中。我错过了什么?