Skip to content

Instantly share code, notes, and snippets.

@anarcher
Created September 22, 2010 12:34
Show Gist options
  • Save anarcher/591584 to your computer and use it in GitHub Desktop.
Save anarcher/591584 to your computer and use it in GitHub Desktop.
google app engine URLFetch scala example
import com.google.appengine.api.urlfetch._
import java.net.URL
import java.net.URLEncoder
val urlFetch = URLFetchServiceFactory.getURLFetchService()
val url = new URL("http://me2day.net/api/get_posts/anarch.json")
val req = new HTTPRequest(url,HTTPMethod.GET)
val params = Map("scope" -> "all")
val qs = Map(params : _* ).foldLeft("")((qs,p) => { (if(qs != "") qs+"&" else qs)+"%s=%s".format(p._1,p._2) })
req.setPayload(qs.getBytes)
val res = urlFetch.fetch(req)
val content = new String(res.getContent)
//ref: http://groups.google.com/group/google-appengine/browse_thread/thread/2ce349fd030cef48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment