Advertisement
wandrake

Untitled

Nov 26th, 2013
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.71 KB | None | 0 0
  1. object RESTConnectohr {
  2.   def doGET(
  3.     url_string: String,
  4.     vars: Option[Map[String, String]] = None,
  5.     headers: Option[Map[String, String]] = None): Pair[Int, String] = {
  6.  
  7.     val get_params: String = vars match {
  8.       case Some(q) => q
  9.         .map((x: (String, String)) => x._1 + "=" + URLEncoder.encode(x._2, "ISO-8859-1"))
  10.         .mkString("&")
  11.       case _ => ""
  12.     }
  13.  
  14.     val url: URL = new URL(url_string + get_params)
  15.  
  16.     val conn: HttpURLConnection = url
  17.       .openConnection()
  18.       .asInstanceOf[HttpURLConnection]
  19.     conn.setRequestMethod("GET")
  20.  
  21.     headers.map(_.map((x) => conn.setRequestProperty(x._1, x._2)))
  22.  
  23.     (conn.getResponseCode(), conn.getResponseMessage())
  24.   }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement