我想用用戶名和密碼從服務器獲取認證密鑰發送請求,這裏是我的代碼,我不知道如何用請求發送給參數,請幫我解決它。HTTP在Swift中發送請求參數
let urlString = "http://services.84069.ir/Restful/PaymentService.svc/authenticate"
func recentProfileURL(parameter : [String:String]?) -> NSURL {
let component = NSURLComponents(string: urlString)!
var queryItem = [NSURLQueryItem]()
if let param = parameter {
for (key,value) in param {
let item = NSURLQueryItem(name: key, value: value)
queryItem.append(item)
}
}
component.queryItems = queryItem
return component.URL!
}
func fetchCode(completion completion: (ProfileResult) -> Void){
let request = NSURLRequest(URL: recentProfileURL(["UserName": self.userNameParam]))
let task = session.dataTaskWithRequest(request, completionHandler: {
(data, response, error) in
let result = self.processUserProfileRequest(data: data, error: error)
completion(result)
})
task.resume()
}
我試圖爲獲得認證碼從服務器如何可以發送參數的陣列,而不是一個參數發送用戶名和密碼?
試試這個也許這將是對您有用! http://stackoverflow.com/questions/40108462/swift-ios-mobile-app-login-submit/40108876#40108876 –