Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. func getServerResponse(){
  2. var request=URLRequest(url: URL(string: "http://dev.example.com/Api/Account")!)
  3. let configuration=URLSessionConfiguration.default
  4. request.httpMethod="GET"
  5. let task=URLSession.init(configuration: configuration).dataTask(with: request, completionHandler: {(data,response,error) -> Void in
  6.  
  7. do {
  8. if let jsonResult = try JSONSerialization.jsonObject(with: data!, options: []) as? NSDictionary {
  9. print("Result-->(jsonResult)")
  10. print((response as! HTTPURLResponse).statusCode)
  11. }
  12. } catch let error as NSError {
  13. print(error.localizedDescription)
  14. }
  15. })
  16.  
  17. task.resume()
  18.  
  19. }
  20.  
  21. func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
  22. let crdential = URLCredential.init(user:"userName", password: "password", persistence: URLCredential.Persistence.none)
  23. completionHandler(URLSession.AuthChallengeDisposition.useCredential, crdential)
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement