【发布时间】:2018-04-11 14:43:33
【问题描述】:
我也测试了这个链接。给我不好的请求(400)
使用原生库而不是 almafire
这是我偷偷摸摸的链接 send object as parameter
请给我投票
这是我的完整代码
guard let url=URL(string: "http://test.com/google/getAddress") else{return}
let parameters=GoogleMap()
var requst=URLRequest(url: url)
requst.httpMethod="POST"
requst.addValue("application/json", forHTTPHeaderField: "Content-Type")
requst.httpMethod="POST"
guard let httpbody=try? JSONSerialization.data(withJSONObject: parameters, options: []) else{return}
requst.httpBody=httpbody
print(url)
let _=URLSession.shared.dataTask(with: requst) { (data, response, error) in
if let data=data{
do{
let json=try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers)
print(json)
}
catch{
print(error)
}
}
}.resume()
}
我的模型类
class Model {
private var latitude:Double?
private var longitude:Double?
var _latitude:Double{
get{
return latitude!
}
set{
latitude=newValue
}
}
var _longitude:Double{
get{
return longitude!
}
set{
longitude=newValue
}
}
func toJSON() -> [String: Any] {
return [ "latitude": latitude as Any, "longtide": longitude as Any]
}
}
我已经作为字典进行了测试,但服务器在其 JSON 响应中给了我“错误请求”错误。
【问题讨论】: