Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object RESTConnectohr {
- def doGET(
- url_string: String,
- vars: Option[Map[String, String]] = None,
- headers: Option[Map[String, String]] = None): Pair[Int, String] = {
- val get_params: String = vars match {
- case Some(q) => q
- .map((x: (String, String)) => x._1 + "=" + URLEncoder.encode(x._2, "ISO-8859-1"))
- .mkString("&")
- case _ => ""
- }
- val url: URL = new URL(url_string + get_params)
- val conn: HttpURLConnection = url
- .openConnection()
- .asInstanceOf[HttpURLConnection]
- conn.setRequestMethod("GET")
- headers.map(
- _.map((x: (String, String)) => conn.setRequestProperty(x._1, x._2))
- )
- (conn.getResponseCode(), conn.getResponseMessage())
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement