我已使用此代码连接到服务
let login = ["FCAI":"1"]
let url = NSURL(string: "https//172.13.12.2/Image/serive.svc/GetImage")!
let session = NSURLSession.sharedSession()
let request = NSMutableURLRequest(URL: url)
do {
let auth = try NSJSONSerialization.dataWithJSONObject(login, options: .PrettyPrinted)
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.HTTPMethod = "POST"
request.HTTPBody = auth
let task = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
print("Got response \(response) with error \(error)")
print("Done.")
})
task.resume()
} catch {
print("Error")
}
但响应始终是状态400 错误是:
服务器在请求中遇到错误处理。异常消息是'反序列化system.string类型的对象时出错。结束元素' root'来自命名空间'。