eja08
eja08

Reputation: 4840

Is there a way to quit browser session in Swift or RxAlamofire?

I am web scrapping a specific website to which the user has to be logged in. It is simple to logout the user, but after the logout the site requires the user to "close the browser". If the user only closes the tab and then re-enters the site, they are taken back to the signed in account. Is there a way to somehow simulate closing the browser in Swift or possibly RxAlamofire?

Upvotes: 0

Views: 85

Answers (1)

Josh Homann
Josh Homann

Reputation: 16327

The ephemeral session configuration is designed to not persist or cache and information to disk (its only in RAM). Create an ephemeral session, use it, throw it away and create another one and it will not have any persisted information.

let session = URLSession(configuration: URLSessionConfiguration.ephemeral)
session.dataTask(with: myURL) { data, response, error in
    // Do stuff here
}.resume()

EDIT:

Since Alamofire rx just extends URLSession you can similarly do:

let session = URLSession(configuration: URLSessionConfiguration.ephemeral)
session
   .rx
   .json(.get, url)
   .observeOn(MainScheduler.instance)
   .subscribe {
      // Do stuff here
   }

Upvotes: 1

Related Questions