Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func getServerResponse(){
- var request=URLRequest(url: URL(string: "http://dev.example.com/Api/Account")!)
- let configuration=URLSessionConfiguration.default
- request.httpMethod="GET"
- let task=URLSession.init(configuration: configuration).dataTask(with: request, completionHandler: {(data,response,error) -> Void in
- do {
- if let jsonResult = try JSONSerialization.jsonObject(with: data!, options: []) as? NSDictionary {
- print("Result-->(jsonResult)")
- print((response as! HTTPURLResponse).statusCode)
- }
- } catch let error as NSError {
- print(error.localizedDescription)
- }
- })
- task.resume()
- }
- func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
- let crdential = URLCredential.init(user:"userName", password: "password", persistence: URLCredential.Persistence.none)
- completionHandler(URLSession.AuthChallengeDisposition.useCredential, crdential)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement