Created
March 4, 2014 06:35
-
-
Save seamusv/9341374 to your computer and use it in GitHub Desktop.
Spray.io Scaper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit val system = ActorSystem("nwtel-cable-usage") | |
implicit val timeout = Timeout(60000) | |
import system.dispatcher | |
def extractSessionCookies(httpResponse: HttpResponse) = httpResponse.headers.collect { case `Set-Cookie`(hc) => Cookie(hc) } | |
val macAddress = "7CB21B9D69AE" | |
val query = for { | |
Http.HostConnectorInfo(connector, _) <- IO(Http) ? Http.HostConnectorSetup("apps.nwtel.ca", port = 443, sslEncryption = true) | |
withoutSession <- Futures.successful { sendReceive(connector) } | |
loginPage <- withoutSession(Get("/cable_usage/secured/index.jsp")) | |
withSession <- Futures.successful { addHeaders(extractSessionCookies(loginPage)) ~> sendReceive(connector) } | |
authenticate <- withSession(Post("/cable_usage/j_security_check", FormData(Map("j_target_url" -> "secured/index.jsp", "j_username" -> macAddress, "j_password" -> "123456", "MAC" -> macAddress, "submit_btn" -> "Submit")))) | |
usage <- withSession(Get("/cable_usage/secured/index.jsp")) | |
} yield usage | |
query onComplete { | |
case Success(httpResponse) => | |
println(httpResponse.entity.data.asString) | |
case Failure(e) => | |
e.printStackTrace() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment