0
我是iOS的初學者。我想要做的是: 通過郵遞員從服務器獲取數據,將郵遞員&中的代碼複製到Xcode中。 Xcode顯示錯誤,我卡住了。因爲我是初學者,所以無法擺脫這些錯誤。代碼中的錯誤Swift/Xcode/Postman
class ViewController: UIViewController/*, UITableViewDataSource, UITableViewDelegate, HomeModelProtocol */{
override func viewDidLoad() {
super.viewDidLoad()
}
let headers = [
"content-type": "application/json",
"authorization": "Basic Og==",
"cache-control": "no-cache",
"postman-token": "212506d2-d231-a462-8f6a-b0ec38f884e4"
]
let postData = NSData(data: "{ flight_type: "Arrival" , fromdate: "17-Mar- 2017" }".data(using: String.Encoding.utf8)!)
let request = NSMutableURLRequest(url: NSURL(string: "http://<servername>.ashx")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error!)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse!)
}
})
dataTask.resume()
}class ViewController: UIViewController/*, UITableViewDataSource, UITableViewDelegate, HomeModelProtocol */{
override func viewDidLoad() {
super.viewDidLoad()
}
let headers = [
"content-type": "application/json",
"authorization": "Basic Og==",
"cache-control": "no-cache",
"postman-token": "212506d2-d231-a462-8f6a-b0ec38f884e4"
]
let postData = NSData(data: "{ flight_type: "Arrival" , fromdate: "17-Mar- 2017" }".data(using: String.Encoding.utf8)!)
let request = NSMutableURLRequest(url: NSURL(string: "http://mywallet.pk/api/flightschedule.ashx")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error!)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse!)
}
})
dataTask.resume()
}
已經導入! –
你得到了什麼具體的錯誤,你想達到什麼目的? –
https://i.stack.imgur.com/kQ8ax.png –