2
發送參數JSON這是我的終點的樣子:斯威夫特莫亞在請求主體
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。我錯過了什麼?