2017年1月4日 | Leave a comment 问题: Swift3 如何使用iOS系统类库 实现http post 解决: Swift func testPost(){ let req : NSMutableURLRequest = NSMutableURLRequest(url:URL(string:"http://192.168.26.1:8080/web/api/user/login")!) req.httpBody = "userName=是奋斗史&md5Password=fdsafdsa".data(using: .utf8); req.httpMethod = "POST" URLSession.shared.dataTask(with: req as URLRequest) { (data:Data?, resp:URLResponse?, error:Error?) in print("data:\(data) resp:\(resp) error:\(error)"); }.resume() Thread.sleep(forTimeInterval: 5); } 12345678910 func testPost(){ let req : NSMutableURLRequest = NSMutableURLRequest(url:URL(string:"http://192.168.26.1:8080/web/api/user/login")!) req.httpBody = "userName=是奋斗史&md5Password=fdsafdsa".data(using: .utf8); req.httpMethod = "POST" URLSession.shared.dataTask(with: req as URLRequest) { (data:Data?, resp:URLResponse?, error:Error?) in print("data:\(data) resp:\(resp) error:\(error)"); }.resume() Thread.sleep(forTimeInterval: 5); }